diff options
| author | Aetias <aetias@outlook.com> | 2024-10-21 20:36:15 +0200 |
|---|---|---|
| committer | Aetias <aetias@outlook.com> | 2024-10-21 20:36:15 +0200 |
| commit | a62cc074e93cdd77605bddcd145a96d3cfa7618d (patch) | |
| tree | 31f0d5bf0872b316643d543957ea2a6d22e632e2 /include/System/Random.hpp | |
| parent | 5c3e3aee99af35884462f518a9bc1fbf65ae92d4 (diff) | |
| parent | f4c5e4862419a14487575bf477118458c0e4a289 (diff) | |
Merge branch 'main' into actor-manager
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; |
