[+] IRandomDevice::NextUUID

This commit is contained in:
Reece Wilson 2023-12-29 22:57:25 +00:00
parent b3557ed938
commit 063aa5c548
3 changed files with 16 additions and 1 deletions

View File

@ -26,6 +26,7 @@ namespace Aurora::RNG
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 Memory::MemoryViewRead ToSeed() = 0;

View File

@ -305,6 +305,20 @@ namespace Aurora::RNG
return this->UniformFloatInRange(kDblEpsilon, dRange + kDblEpsilon) + dMin - kDblEpsilon;
}
uuids::uuid RandomDevice::NextUUID()
{
AuUInt8 bytes[16];
this->Read(bytes);
bytes[8] &= 0xBF;
bytes[8] |= 0x80;
bytes[6] &= 0x4F;
bytes[6] |= 0x40;
return uuids::uuid { bytes, bytes + 16 };
}
AuMemoryViewRead RandomDevice::ToSeed()
{
if (this->def_.bSecure)

View File

@ -29,7 +29,7 @@ namespace Aurora::RNG
double NextDecimal() override;
double NextNumber(double dMin, double dMax) override;
AuUInt32 NextIndex(AuUInt32 uCount /* = max + 1*/) override;
uuids::uuid NextUUID() override;
AuMemoryViewRead ToSeed() override;
void Init(const RandomDef &def);