2021-11-05 17:34:23 +00:00
|
|
|
/***
|
2021-09-06 10:58:08 +00:00
|
|
|
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
|
|
|
|
{
|
2023-10-17 09:03:15 +00:00
|
|
|
static const auto kSizeRNGDevice = 256;
|
|
|
|
|
2022-09-19 01:34:57 +00:00
|
|
|
struct IRandomDevice
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2024-01-01 14:10:42 +00:00
|
|
|
virtual void Read(Memory::MemoryViewWrite view) = 0;
|
|
|
|
|
|
|
|
virtual AuString NextString(AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
|
|
|
|
virtual void NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
|
|
|
|
virtual AuUInt8 NextByte() = 0;
|
|
|
|
virtual bool NextBoolean() = 0;
|
|
|
|
virtual AuUInt32 NextU32() = 0;
|
|
|
|
virtual AuUInt32 NextU32Range(AuUInt32 uMin, AuUInt32 uMax) = 0;
|
|
|
|
virtual AuUInt64 NextU64() = 0;
|
|
|
|
virtual AuInt32 NextI32Range(AuInt32 iMin, AuInt32 iMax) = 0;
|
|
|
|
virtual double NextDecimal() = 0;
|
|
|
|
virtual double NextNumber(double dMin, double dMax) = 0;
|
|
|
|
virtual AuUInt32 NextIndex(AuUInt32 uCount /* = max + 1*/) = 0;
|
|
|
|
virtual uuids::uuid NextUUID() = 0;
|
|
|
|
virtual AuList<AuInt32> NextArrayI32Range(AuUInt32 uCount, AuInt32 iMin, AuInt32 iMax) = 0;
|
|
|
|
virtual AuList<AuUInt32> NextArrayU32Range(AuUInt32 uCount, AuUInt32 uMin, AuUInt32 uMax) = 0;
|
|
|
|
virtual AuList<double> NextArrayDoubleRange(AuUInt32 uCount, double dMin, double dMax) = 0;
|
|
|
|
virtual AuList<AuInt32> NextArrayI32(AuUInt32 uCount) = 0;
|
|
|
|
virtual AuList<AuUInt32> NextArrayU32(AuUInt32 uCount) = 0;
|
|
|
|
virtual AuList<double> NextArrayDouble(AuUInt32 uCount) = 0;
|
|
|
|
virtual AuList<double> NextArrayDecimals(AuUInt32 uCount) = 0;
|
|
|
|
virtual AuList<uuids::uuid> NextArrayUUIDs(AuUInt32 uCount) = 0;
|
2022-12-28 20:07:41 +00:00
|
|
|
|
2024-01-03 23:52:57 +00:00
|
|
|
virtual IO::IStreamReader *ToStreamReader() = 0;
|
2022-12-28 20:07:41 +00:00
|
|
|
virtual Memory::MemoryViewRead ToSeed() = 0;
|
2021-09-06 10:58:08 +00:00
|
|
|
|
|
|
|
template<typename T, int N>
|
2022-02-20 20:43:37 +00:00
|
|
|
inline void NextFillArray(T(&array)[N])
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-01-15 06:05:22 +00:00
|
|
|
Read(Memory::MemoryViewWrite(array));
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
2022-02-20 20:43:37 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2023-01-15 06:05:22 +00:00
|
|
|
inline void NextFillArray(T *pArray, AuUInt32 uCount)
|
2022-02-20 20:43:37 +00:00
|
|
|
{
|
2023-01-15 06:05:22 +00:00
|
|
|
Read(Memory::MemoryViewWrite(pArray, uCount * sizeof(T)));
|
2022-02-20 20:43:37 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
template<typename T>
|
2023-04-19 02:17:45 +00:00
|
|
|
void NextFillRange(T &container)
|
2022-09-30 09:53:29 +00:00
|
|
|
{
|
|
|
|
NextFillArray(container.begin(), container.end() - container.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void NextFillBuffer(Memory::ByteBuffer &buffer)
|
|
|
|
{
|
|
|
|
auto view = buffer.GetNextLinearWrite();
|
|
|
|
NextFillRange(view);
|
|
|
|
buffer.writePtr += view.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
inline void NextFillRange(Memory::ByteBuffer &buffer)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2022-09-30 09:53:29 +00:00
|
|
|
NextFillBuffer(buffer);
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2022-02-20 20:43:37 +00:00
|
|
|
inline T NextFillTmpl()
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
|
|
|
T ret {};
|
2023-01-15 06:05:22 +00:00
|
|
|
Read(Memory::MemoryViewWrite(&ret, sizeof(T)));
|
2021-09-06 10:58:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2022-02-20 20:43:37 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2024-01-17 17:46:31 +00:00
|
|
|
inline T NextIterator(T begin, T end)
|
2022-02-20 20:43:37 +00:00
|
|
|
{
|
2024-01-17 17:46:31 +00:00
|
|
|
auto nextItr = begin;
|
|
|
|
auto uCount = std::distance(begin, end);
|
|
|
|
std::advance(nextItr, NextIndex(uCount));
|
|
|
|
return nextItr;
|
2022-02-20 20:43:37 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
template<typename T>
|
2023-01-15 06:05:22 +00:00
|
|
|
inline T &NextArray(T *pItems, AuUInt32 uCount)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-01-15 06:05:22 +00:00
|
|
|
return pItems[NextIndex(uCount)];
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
2024-01-17 17:46:31 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline auto NextRange(T &items)
|
|
|
|
{
|
|
|
|
return NextIterator(items.begin(), items.end());
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
template<typename T>
|
2023-04-19 02:17:45 +00:00
|
|
|
inline T &NextVector(AuList<T> &items)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2024-01-17 17:46:31 +00:00
|
|
|
return *NextRange(items);
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
2022-02-20 20:25:39 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2024-01-17 17:46:31 +00:00
|
|
|
inline const T &NextVector(const AuList<T> &items)
|
2022-02-20 20:25:39 +00:00
|
|
|
{
|
2024-01-17 17:46:31 +00:00
|
|
|
return *NextRange(items);
|
2022-02-20 20:25:39 +00:00
|
|
|
}
|
2021-09-06 10:58:08 +00:00
|
|
|
};
|
|
|
|
|
2023-10-17 09:03:15 +00:00
|
|
|
AUKN_SHARED_SOO2(Random, IRandomDevice, kSizeRNGDevice,
|
|
|
|
((const RandomDef &, def)),
|
|
|
|
const RandomDef &def);
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|