107 lines
2.3 KiB
C++
107 lines
2.3 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: RandomDef.hpp
|
|
Date: 2022-2-6
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::RNG
|
|
{
|
|
struct RandomDef
|
|
{
|
|
AU_COPY_MOVE_DEF(RandomDef);
|
|
|
|
inline RandomDef(AuUInt32 seed)
|
|
{
|
|
this->SetSeed(seed);
|
|
}
|
|
|
|
inline RandomDef(AuUInt64 seed)
|
|
{
|
|
this->SetSeed64(seed);
|
|
}
|
|
|
|
inline RandomDef(const AuArray<AuUInt8, 64> &seed)
|
|
{
|
|
this->SetMassiveSeed(seed);
|
|
}
|
|
|
|
cstatic RandomDef Secure()
|
|
{
|
|
RandomDef def;
|
|
def.SetCSRNG();
|
|
return AuMove(def);
|
|
}
|
|
|
|
cstatic RandomDef Fast()
|
|
{
|
|
return RandomDef {};
|
|
}
|
|
|
|
cstatic RandomDef FromU64Seed(AuUInt64 uSeed)
|
|
{
|
|
RandomDef def(uSeed);
|
|
return AuMove(def);
|
|
}
|
|
|
|
cstatic RandomDef FromU32Seed(AuUInt32 uSeed)
|
|
{
|
|
RandomDef def(uSeed);
|
|
return AuMove(def);
|
|
}
|
|
|
|
cstatic RandomDef FromMassiveSeed(const AuArray<AuUInt8, 64> &seed)
|
|
{
|
|
RandomDef def;
|
|
def.SetMassiveSeed(seed);
|
|
return AuMove(def);
|
|
}
|
|
|
|
bool bSecure {};
|
|
AuOptional<AuUInt32> seed;
|
|
AuOptional<AuUInt64> seed64;
|
|
AuOptional<AuArray<AuUInt8, 64>> seedMassive;
|
|
|
|
inline auline void SetSeed(AuUInt32 seed)
|
|
{
|
|
Reset();
|
|
this->seed = seed;
|
|
this->bSecure = false;
|
|
}
|
|
|
|
inline auline void SetSeed64(AuUInt64 seed)
|
|
{
|
|
Reset();
|
|
this->seed64 = seed;
|
|
this->bSecure = false;
|
|
}
|
|
|
|
inline auline void SetMassiveSeed(const AuArray<AuUInt8, 64> &seed)
|
|
{
|
|
Reset();
|
|
this->seedMassive = seed;
|
|
this->bSecure = false;
|
|
}
|
|
|
|
inline auline void SetCSRNG()
|
|
{
|
|
Reset();
|
|
this->bSecure = true;
|
|
}
|
|
|
|
inline auline void SetQuickRng()
|
|
{
|
|
Reset();
|
|
}
|
|
|
|
inline auline void Reset()
|
|
{
|
|
this->bSecure = false;
|
|
this->seed.reset();
|
|
this->seed64.reset();
|
|
this->seedMassive.reset();
|
|
}
|
|
};
|
|
} |