/*** 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 { static const auto kSizeRNGDevice = 256; struct IRandomDevice { 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 AuInt32 NextI32Range(AuInt32 iMin, AuInt32 iMax) = 0; virtual AuUInt64 NextU64() = 0; virtual AuUInt64 NextU64Range(AuUInt64 uMin, AuUInt64 uMax) = 0; virtual AuInt64 NextI64Range(AuInt64 iMin, AuInt64 iMax) = 0; virtual AuVec2 NextVec2(AuVec2 boundA, AuVec2 boundB) = 0; virtual AuVec2 NextVec2Sorted(AuVec2 min, AuVec2 max) = 0; virtual AuVec3 NextVec3(AuVec3 boundA, AuVec3 boundB) = 0; virtual AuVec3 NextVec3Sorted(AuVec3 min, AuVec3 max) = 0; virtual AuVec4 NextVec4(AuVec4 boundA, AuVec4 boundB) = 0; virtual AuVec4 NextVec4Sorted(AuVec4 min, AuVec4 max) = 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 NextArrayI32Range(AuUInt32 uCount, AuInt32 iMin, AuInt32 iMax) = 0; virtual AuList NextArrayU32Range(AuUInt32 uCount, AuUInt32 uMin, AuUInt32 uMax) = 0; virtual AuList NextArrayI64Range(AuUInt32 uCount, AuInt64 iMin, AuInt64 iMax) = 0; virtual AuList NextArrayU64Range(AuUInt32 uCount, AuUInt64 uMin, AuUInt64 uMax) = 0; virtual AuList NextArrayU32Mask(AuUInt32 uCount, AuUInt32 uMask) = 0; virtual AuList NextArrayU64Mask(AuUInt32 uCount, AuUInt64 uMask) = 0; virtual AuList NextArrayDoubleRange(AuUInt32 uCount, double dMin, double dMax) = 0; virtual AuList NextArrayDoubleRangeFast(AuUInt32 uCount, double dMin, double dMax) = 0; virtual AuList NextArrayI32(AuUInt32 uCount) = 0; virtual AuList NextArrayU32(AuUInt32 uCount) = 0; virtual AuList NextArrayI64(AuUInt32 uCount) = 0; virtual AuList NextArrayU64(AuUInt32 uCount) = 0; virtual AuList NextArrayVec2(AuUInt32 uCount, AuVec2 boundA, AuVec2 boundB) = 0; virtual AuList NextArrayVec2Sorted(AuUInt32 uCount, AuVec2 min, AuVec2 max) = 0; virtual AuList NextArrayVec2SortedFast(AuUInt32 uCount, AuVec2 min, AuVec2 max) = 0; virtual AuList NextArrayVec3(AuUInt32 uCount, AuVec3 boundA, AuVec3 boundB) = 0; virtual AuList NextArrayVec3Sorted(AuUInt32 uCount, AuVec3 min, AuVec3 max) = 0; virtual AuList NextArrayVec3SortedFast(AuUInt32 uCount, AuVec3 min, AuVec3 max) = 0; virtual AuList NextArrayVec4(AuUInt32 uCount, AuVec4 boundA, AuVec4 boundB) = 0; virtual AuList NextArrayVec4Sorted(AuUInt32 uCount, AuVec4 min, AuVec4 max) = 0; virtual AuList NextArrayVec4SortedFast(AuUInt32 uCount, AuVec4 min, AuVec4 max) = 0; virtual AuList NextArrayDouble(AuUInt32 uCount) = 0; virtual AuList NextArrayDecimals(AuUInt32 uCount) = 0; virtual AuList NextArrayDecimalsFast(AuUInt32 uCount) = 0; virtual AuList NextArrayUUIDs(AuUInt32 uCount) = 0; virtual IO::IStreamReader *ToStreamReader() = 0; virtual Memory::MemoryViewRead ToSeed() = 0; template inline void NextFillArray(T(&array)[N]) { Read(Memory::MemoryViewWrite(array)); } template inline void NextFillArray(T *pArray, AuUInt32 uCount) { Read(Memory::MemoryViewWrite(pArray, uCount * sizeof(T))); } template void NextFillRange(T &container) { 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) { NextFillBuffer(buffer); } template inline T NextFillTmpl() { T ret {}; Read(Memory::MemoryViewWrite(&ret, sizeof(T))); return ret; } template inline T NextIterator(T begin, T end) { auto nextItr = begin; auto uCount = std::distance(begin, end); std::advance(nextItr, NextIndex(uCount)); return nextItr; } template inline T &NextArray(T *pItems, AuUInt32 uCount) { return pItems[NextIndex(uCount)]; } template inline auto NextRange(T &items) { return NextIterator(items.begin(), items.end()); } template inline T &NextList(AuList &items) { return *NextRange(items); } template inline const T &NextList(const AuList &items) { return *NextRange(items); } template inline void ShuffleIterators(T begin, T end) { AU_DEBUG_MEMCRUNCH; auto uCount = std::distance(begin, end); auto nextIndexArray = this->NextArrayU32Range(uCount, 0, uCount - 1); for (AU_ITERATE_N(i, AuUInt(uCount))) { auto nextItrA = begin; auto nextItrB = begin; std::advance(nextItrA, i); std::advance(nextItrB, nextIndexArray[i]); AuSwap(*nextItrA, *nextItrB); } } template inline void ShuffleList(AuList &list) { this->ShuffleIterators(list.begin(), list.end()); } }; AUKN_SHARED_SOO2(Random, IRandomDevice, kSizeRNGDevice, ((const RandomDef &, def)), const RandomDef &def); }