diff options
| author | Aetias <aetias@outlook.com> | 2024-10-20 10:39:09 +0200 |
|---|---|---|
| committer | Aetias <aetias@outlook.com> | 2024-10-20 10:39:09 +0200 |
| commit | fb9d00b87f47a043b1f4a314be6607085947d3c8 (patch) | |
| tree | c00aaee39447887818cddee5600a209ad10a24b6 /include/System/Random.hpp | |
| parent | 8181d30b8731685395f7499117648413ae3898a3 (diff) | |
Fix build; add RNG code
Diffstat (limited to 'include/System/Random.hpp')
| -rw-r--r-- | include/System/Random.hpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/System/Random.hpp b/include/System/Random.hpp new file mode 100644 index 00000000..4506466d --- /dev/null +++ b/include/System/Random.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "global.h" +#include "types.h" + +struct Random { + /* 00 */ u64 mRandomValue; + /* 08 */ u64 mFactor; + /* 10 */ u64 mAddend; + /* 18 */ + + /** + * Generate a random number from 0 (inclusive) to `max` (exclusive) + */ + inline u32 Next(u32 max) { + mRandomValue = mAddend + mFactor * mRandomValue; + u64 result = (mRandomValue >> 32) * max; + return result >> 32; + } +}; + +extern Random *gRandom; |
