[+] AuRNG::IRandomDevice::...InView

[+] AuRNG::...InView

(amended mixed tabs)
This commit is contained in:
Reece Wilson 2024-07-21 03:37:07 +01:00
parent 8be1afe570
commit ecf8dc6f0b
5 changed files with 1247 additions and 656 deletions

View File

@ -13,10 +13,14 @@ namespace Aurora::RNG
struct IRandomDevice
{
virtual IO::IStreamReader * ToStreamReader() = 0;
virtual Memory::MemoryViewRead ToSeed() = 0;
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;
@ -35,6 +39,30 @@ namespace Aurora::RNG
virtual double NextNumber(double dMin, double dMax) = 0;
virtual AuUInt32 NextIndex(AuUInt32 uCount /* = max + 1*/) = 0;
virtual uuids::uuid NextUUID() = 0;
// Note: Fast arrays are deterministic with little seed entropy (usually 64bits, sometimes 32bits).
//
// Wont mitigate; use the slower non-fast variants if each numeric value (if not vec) OR
// a *group* of N-components of each vector (if vec) need to be unique.
//
// Fast arrays simply rehash the previous bits to get the next component. While hopefully
// perfectly uniform (otherwise the hash wouldn't be a good hash), it's entirely possible
// to extrapolate the next value in the sequence.
//
// In addition, this applies to non-fast components of each vector; given an X component,
// you can derive the Y and Z, even under non-fast functions. Fast vectors means the next
// vector can be extrapolated from the previous group of vector components; nonfast, you
// can only solve Y and Z. Fast vector arrays only have 64bits of entropy extrapolated to
// 52bits * uCount * N bits of fully deterministic components; nonfast vector arrays have
// 64bits * uCount bits of entropy, extrapolated to 52bits * uCount * N bits of partially
// in-vector extrapolatable bits.
//
// Also note, it might not even be possible to extrapolate these components in practice.
// This is because each component has some bits chucked away when shoving the seed into
// the mantissa, and then each component gets manipulated using the same range provided
// by the bound[..]s or min/max vecs parameters. Some bruteforce would be required.
//
virtual AuList<AuInt32> NextArrayI32Range(AuUInt32 uCount, AuInt32 iMin, AuInt32 iMax) = 0;
virtual AuList<AuInt32> NextArrayI32RangeFast(AuUInt32 uCount, AuInt32 iMin, AuInt32 iMax) = 0;
virtual AuList<AuUInt32> NextArrayU32Range(AuUInt32 uCount, AuUInt32 uMin, AuUInt32 uMax) = 0;
@ -67,9 +95,39 @@ namespace Aurora::RNG
virtual AuList<double> NextArrayDecimals(AuUInt32 uCount) = 0;
virtual AuList<double> NextArrayDecimalsFast(AuUInt32 uCount) = 0;
virtual AuList<uuids::uuid> NextArrayUUIDs(AuUInt32 uCount) = 0;
virtual AuUInt NextArrayI32RangeInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax) = 0;
virtual AuUInt NextArrayI32RangeFastInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax) = 0;
virtual AuUInt NextArrayU32RangeInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax) = 0;
virtual AuUInt NextArrayU32RangeFastInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax) = 0;
virtual AuUInt NextArrayI64RangeInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax) = 0;
virtual AuUInt NextArrayI64RangeFastInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax) = 0;
virtual AuUInt NextArrayU64RangeInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax) = 0;
virtual AuUInt NextArrayU64RangeFastInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax) = 0;
virtual AuUInt NextArrayU32MaskInView(Memory::MemoryViewWrite write, AuUInt32 uMask) = 0;
virtual AuUInt NextArrayU64MaskInView(Memory::MemoryViewWrite write, AuUInt64 uMask) = 0;
virtual AuUInt NextArrayDoubleRangeInView(Memory::MemoryViewWrite write, double dMin, double dMax) = 0;
virtual AuUInt NextArrayDoubleRangeFastInView(Memory::MemoryViewWrite write, double dMin, double dMax) = 0;
virtual AuUInt NextArrayI32InView(Memory::MemoryViewWrite write) = 0;
virtual AuUInt NextArrayU32InView(Memory::MemoryViewWrite write) = 0;
virtual AuUInt NextArrayI64InView(Memory::MemoryViewWrite write) = 0;
virtual AuUInt NextArrayU64InView(Memory::MemoryViewWrite write) = 0;
virtual AuUInt NextArrayVec2InView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB) = 0;
virtual AuUInt NextArrayVec2FastInView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB) = 0;
virtual AuUInt NextArrayVec2SortedInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max) = 0;
virtual AuUInt NextArrayVec2SortedFastInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max) = 0;
virtual AuUInt NextArrayVec3InView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB) = 0;
virtual AuUInt NextArrayVec3FastInView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB) = 0;
virtual AuUInt NextArrayVec3SortedInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max) = 0;
virtual AuUInt NextArrayVec3SortedFastInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max) = 0;
virtual AuUInt NextArrayVec4InView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB) = 0;
virtual AuUInt NextArrayVec4FastInView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB) = 0;
virtual AuUInt NextArrayVec4SortedInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max) = 0;
virtual AuUInt NextArrayVec4SortedFastInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max) = 0;
virtual AuUInt NextArrayDoubleInView(Memory::MemoryViewWrite write) = 0;
virtual AuUInt NextArrayDecimalsInView(Memory::MemoryViewWrite write) = 0;
virtual AuUInt NextArrayDecimalsFastInView(Memory::MemoryViewWrite write) = 0;
virtual AuUInt NextArrayUUIDsInView(Memory::MemoryViewWrite write) = 0;
virtual IO::IStreamReader *ToStreamReader() = 0;
virtual Memory::MemoryViewRead ToSeed() = 0;
template<typename T, int N>
inline void NextFillArray(T(&array)[N])

View File

@ -76,8 +76,40 @@ namespace Aurora::RNG
AUKN_SYM AuList<double> RngArrayDecimals(AuUInt32 uCount);
AUKN_SYM AuList<double> RngArrayDecimalsFast(AuUInt32 uCount);
AUKN_SYM AuList<uuids::uuid> RngArrayUUIDs(AuUInt32 uCount);
// Note: it is conceivable that someone may want the following templates for some cryptographic purpose
AUKN_SYM AuUInt RngArrayI32RangeInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax);
AUKN_SYM AuUInt RngArrayI32RangeFastInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax);
AUKN_SYM AuUInt RngArrayU32RangeInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax);
AUKN_SYM AuUInt RngArrayU32RangeFastInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax);
AUKN_SYM AuUInt RngArrayI64RangeInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax);
AUKN_SYM AuUInt RngArrayI64RangeFastInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax);
AUKN_SYM AuUInt RngArrayU64RangeInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax);
AUKN_SYM AuUInt RngArrayU64RangeFastInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax);
AUKN_SYM AuUInt RngArrayU32MaskInView(Memory::MemoryViewWrite write, AuUInt32 uMask);
AUKN_SYM AuUInt RngArrayU64MaskInView(Memory::MemoryViewWrite write, AuUInt64 uMask);
AUKN_SYM AuUInt RngArrayDoubleRangeInView(Memory::MemoryViewWrite write, double dMin, double dMax);
AUKN_SYM AuUInt RngArrayDoubleRangeFastInView(Memory::MemoryViewWrite write, double dMin, double dMax);
AUKN_SYM AuUInt RngArrayI32InView(Memory::MemoryViewWrite write);
AUKN_SYM AuUInt RngArrayU32InView(Memory::MemoryViewWrite write);
AUKN_SYM AuUInt RngArrayI64InView(Memory::MemoryViewWrite write);
AUKN_SYM AuUInt RngArrayU64InView(Memory::MemoryViewWrite write);
AUKN_SYM AuUInt RngArrayVec2InView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB);
AUKN_SYM AuUInt RngArrayVec2FastInView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB);
AUKN_SYM AuUInt RngArrayVec2SortedInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max);
AUKN_SYM AuUInt RngArrayVec2SortedFastInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max);
AUKN_SYM AuUInt RngArrayVec3InView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB);
AUKN_SYM AuUInt RngArrayVec3FastInView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB);
AUKN_SYM AuUInt RngArrayVec3SortedInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max);
AUKN_SYM AuUInt RngArrayVec3SortedFastInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max);
AUKN_SYM AuUInt RngArrayVec4InView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB);
AUKN_SYM AuUInt RngArrayVec4FastInView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB);
AUKN_SYM AuUInt RngArrayVec4SortedInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max);
AUKN_SYM AuUInt RngArrayVec4SortedFastInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max);
AUKN_SYM AuUInt RngArrayDoubleInView(Memory::MemoryViewWrite write);
AUKN_SYM AuUInt RngArrayDecimalsInView(Memory::MemoryViewWrite write);
AUKN_SYM AuUInt RngArrayDecimalsFastInView(Memory::MemoryViewWrite write);
AUKN_SYM AuUInt RngArrayUUIDsInView(Memory::MemoryViewWrite write);
// Note: it is conceivable that someone may want the following templates for some cryptographic purpose
template<bool fast = true, typename T, int N>
static auline void RngFillArray(T(&array)[N])
{

View File

@ -272,4 +272,164 @@ namespace Aurora::RNG
{
return gFastDevice->NextArrayU64RangeFast(uCount, uMin, uMax);
}
AUKN_SYM AuUInt RngArrayI32RangeInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax)
{
return gFastDevice->NextArrayI32RangeInView(write, iMin, iMax);
}
AUKN_SYM AuUInt RngArrayI32RangeFastInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax)
{
return gFastDevice->NextArrayI32RangeFastInView(write, iMin, iMax);
}
AUKN_SYM AuUInt RngArrayU32RangeInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax)
{
return gFastDevice->NextArrayU32RangeInView(write, uMin, uMax);
}
AUKN_SYM AuUInt RngArrayU32RangeFastInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax)
{
return gFastDevice->NextArrayU32RangeFastInView(write, uMin, uMax);
}
AUKN_SYM AuUInt RngArrayI64RangeInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax)
{
return gFastDevice->NextArrayI64RangeInView(write, iMin, iMax);
}
AUKN_SYM AuUInt RngArrayI64RangeFastInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax)
{
return gFastDevice->NextArrayI64RangeFastInView(write, iMin, iMax);
}
AUKN_SYM AuUInt RngArrayU64RangeInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax)
{
return gFastDevice->NextArrayU64RangeInView(write, uMin, uMax);
}
AUKN_SYM AuUInt RngArrayU64RangeFastInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax)
{
return gFastDevice->NextArrayU64RangeFastInView(write, uMin, uMax);
}
AUKN_SYM AuUInt RngArrayU32MaskInView(Memory::MemoryViewWrite write, AuUInt32 uMask)
{
return gFastDevice->NextArrayU32MaskInView(write, uMask);
}
AUKN_SYM AuUInt RngArrayU64MaskInView(Memory::MemoryViewWrite write, AuUInt64 uMask)
{
return gFastDevice->NextArrayU64MaskInView(write, uMask);
}
AUKN_SYM AuUInt RngArrayDoubleRangeInView(Memory::MemoryViewWrite write, double dMin, double dMax)
{
return gFastDevice->NextArrayDoubleRangeInView(write, dMin, dMax);
}
AUKN_SYM AuUInt RngArrayDoubleRangeFastInView(Memory::MemoryViewWrite write, double dMin, double dMax)
{
return gFastDevice->NextArrayDoubleRangeFastInView(write, dMin, dMax);
}
AUKN_SYM AuUInt RngArrayI32InView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayI32InView(write);
}
AUKN_SYM AuUInt RngArrayU32InView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayU32InView(write);
}
AUKN_SYM AuUInt RngArrayI64InView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayI64InView(write);
}
AUKN_SYM AuUInt RngArrayU64InView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayU64InView(write);
}
AUKN_SYM AuUInt RngArrayVec2InView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB)
{
return gFastDevice->NextArrayVec2InView(write, boundA, boundB);
}
AUKN_SYM AuUInt RngArrayVec2FastInView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB)
{
return gFastDevice->NextArrayVec2FastInView(write, boundA, boundB);
}
AUKN_SYM AuUInt RngArrayVec2SortedInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max)
{
return gFastDevice->NextArrayVec2SortedInView(write, min, max);
}
AUKN_SYM AuUInt RngArrayVec2SortedFastInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max)
{
return gFastDevice->NextArrayVec2SortedFastInView(write, min, max);
}
AUKN_SYM AuUInt RngArrayVec3InView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB)
{
return gFastDevice->NextArrayVec3InView(write, boundA, boundB);
}
AUKN_SYM AuUInt RngArrayVec3FastInView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB)
{
return gFastDevice->NextArrayVec3FastInView(write, boundA, boundB);
}
AUKN_SYM AuUInt RngArrayVec3SortedInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max)
{
return gFastDevice->NextArrayVec3SortedInView(write, min, max);
}
AUKN_SYM AuUInt RngArrayVec3SortedFastInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max)
{
return gFastDevice->NextArrayVec3SortedFastInView(write, min, max);
}
AUKN_SYM AuUInt RngArrayVec4InView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB)
{
return gFastDevice->NextArrayVec4InView(write, boundA, boundB);
}
AUKN_SYM AuUInt RngArrayVec4FastInView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB)
{
return gFastDevice->NextArrayVec4FastInView(write, boundA, boundB);
}
AUKN_SYM AuUInt RngArrayVec4SortedInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max)
{
return gFastDevice->NextArrayVec4SortedInView(write, min, max);
}
AUKN_SYM AuUInt RngArrayVec4SortedFastInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max)
{
return gFastDevice->NextArrayVec4SortedFastInView(write, min, max);
}
AUKN_SYM AuUInt RngArrayDoubleInView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayDoubleInView(write);
}
AUKN_SYM AuUInt RngArrayDecimalsInView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayDecimalsInView(write);
}
AUKN_SYM AuUInt RngArrayDecimalsFastInView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayDecimalsFastInView(write);
}
AUKN_SYM AuUInt RngArrayUUIDsInView(Memory::MemoryViewWrite write)
{
return gFastDevice->NextArrayUUIDsInView(write);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -69,6 +69,38 @@ namespace Aurora::RNG
AuList<AuUInt32> NextArrayU32RangeFast(AuUInt32 uCount, AuUInt32 uMin, AuUInt32 uMax) override;
AuList<AuInt64> NextArrayI64RangeFast(AuUInt32 uCount, AuInt64 iMin, AuInt64 iMax) override;
AuList<AuUInt64> NextArrayU64RangeFast(AuUInt32 uCount, AuUInt64 uMin, AuUInt64 uMax) override;
AuUInt NextArrayI32RangeInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax) override;
AuUInt NextArrayI32RangeFastInView(Memory::MemoryViewWrite write, AuInt32 iMin, AuInt32 iMax) override;
AuUInt NextArrayU32RangeInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax) override;
AuUInt NextArrayU32RangeFastInView(Memory::MemoryViewWrite write, AuUInt32 uMin, AuUInt32 uMax) override;
AuUInt NextArrayI64RangeInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax) override;
AuUInt NextArrayI64RangeFastInView(Memory::MemoryViewWrite write, AuInt64 iMin, AuInt64 iMax) override;
AuUInt NextArrayU64RangeInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax) override;
AuUInt NextArrayU64RangeFastInView(Memory::MemoryViewWrite write, AuUInt64 uMin, AuUInt64 uMax) override;
AuUInt NextArrayU32MaskInView(Memory::MemoryViewWrite write, AuUInt32 uMask) override;
AuUInt NextArrayU64MaskInView(Memory::MemoryViewWrite write, AuUInt64 uMask) override;
AuUInt NextArrayDoubleRangeInView(Memory::MemoryViewWrite write, double dMin, double dMax) override;
AuUInt NextArrayDoubleRangeFastInView(Memory::MemoryViewWrite write, double dMin, double dMax) override;
AuUInt NextArrayI32InView(Memory::MemoryViewWrite write) override;
AuUInt NextArrayU32InView(Memory::MemoryViewWrite write) override;
AuUInt NextArrayI64InView(Memory::MemoryViewWrite write) override;
AuUInt NextArrayU64InView(Memory::MemoryViewWrite write) override;
AuUInt NextArrayVec2InView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB) override;
AuUInt NextArrayVec2FastInView(Memory::MemoryViewWrite write, AuVec2 boundA, AuVec2 boundB) override;
AuUInt NextArrayVec2SortedInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max) override;
AuUInt NextArrayVec2SortedFastInView(Memory::MemoryViewWrite write, AuVec2 min, AuVec2 max) override;
AuUInt NextArrayVec3InView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB) override;
AuUInt NextArrayVec3FastInView(Memory::MemoryViewWrite write, AuVec3 boundA, AuVec3 boundB) override;
AuUInt NextArrayVec3SortedInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max) override;
AuUInt NextArrayVec3SortedFastInView(Memory::MemoryViewWrite write, AuVec3 min, AuVec3 max) override;
AuUInt NextArrayVec4InView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB) override;
AuUInt NextArrayVec4FastInView(Memory::MemoryViewWrite write, AuVec4 boundA, AuVec4 boundB) override;
AuUInt NextArrayVec4SortedInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max) override;
AuUInt NextArrayVec4SortedFastInView(Memory::MemoryViewWrite write, AuVec4 min, AuVec4 max) override;
AuUInt NextArrayDoubleInView(Memory::MemoryViewWrite write) override;
AuUInt NextArrayDecimalsInView(Memory::MemoryViewWrite write) override;
AuUInt NextArrayDecimalsFastInView(Memory::MemoryViewWrite write) override;
AuUInt NextArrayUUIDsInView(Memory::MemoryViewWrite write) override;
double NextDecimal() override;
double NextNumber(double dMin, double dMax) override;