AuroraRuntime/Include/Aurora/RNG/IRandomDevice.hpp
Reece 99c5e1fa65 A pretty large patch not worth breaking up into separate commits
[*] Split up Aurora Async
[*] Split Async app into seperate ThreadPool concept
[*] Fix various OSThread bugs and tls transfer issues
[*] Set default affinity to 0xFFFFFFFF
[*] Update Build script
[+] Add AuTuplePopFront
[+] New Network Interface (unimplemented)
[*] Stub out the interfaces required for a better logger
[*] Fix Win32 ShellExecute bug; windows 11 struggles without explicit com init per the docs - now deferring to thread pool
[*] Update gitignore
[*] Follow XDG home standard
[*] Refactor some namespaces to use the shorthand aliases
[*] Various stability fixes
2021-11-05 17:34:23 +00:00

89 lines
2.4 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IRandomDevice.hpp
Date: 2021-9-3
Author: Reece
***/
#pragma once
namespace Aurora::RNG
{
class IRandomDevice
{
public:
virtual void Read(void *in, AuUInt32 length) = 0;
virtual AuString NextString(AuUInt32 length, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
virtual void NextString(char *string, AuUInt32 length, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
virtual AuUInt8 NextByte() = 0;
virtual bool NextBoolean() = 0;
virtual AuUInt32 NextU32() = 0;
virtual AuUInt32 NextU32(AuUInt32 min, AuUInt32 max) = 0;
virtual AuUInt64 NextU64() = 0;
virtual AuInt32 NextInt(AuInt32 min, AuInt32 max) = 0;
virtual double NextDecimal() = 0;
virtual float NextNumber(float min, float max) = 0;
virtual AuUInt32 NextIndex(AuUInt32 count /* = max + 1*/) = 0;
template<typename T, int N>
inline void NextArray(T(&array)[N])
{
Read(array, N * sizeof(T));
}
template<typename T>
inline void NextArray(T *array, AuUInt32 length)
{
Raed(array, length * sizeof(T));
}
template<typename T>
inline T NextTmpl()
{
T ret {};
Read(&ret, sizeof(T));
return ret;
}
template<typename T>
inline T &NextArray(T *items, AuUInt32 count)
{
return items[NextIndex(count)];
}
template<typename T>
inline T &NextVector(const AuList<T> &items)
{
return NextArray(items.data(), items.size());
}
};
struct RandomDef
{
bool secure;
AuOptional<AuUInt32> seed;
AuOptional<AuUInt64> seed64;
inline void SetSeed(AuUInt32 seed)
{
this->seed = seed;
this->secure = false;
}
inline void SetSeed64(AuUInt64 seed)
{
this->seed64 = seed;
this->secure = false;
}
inline void SetCSRNG()
{
this->secure = true;
this->seed.reset();
}
};
AUKN_SHARED_API(Random, IRandomDevice, const RandomDef &def);
}