diff options
| author | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
| commit | fe2baedc760c2f29e2c720f6b1132a2de33c5430 (patch) | |
| tree | dfbe1c72a17805a3cab6e0d47433e9021890c9ca /src/Math/Random.cpp | |
| parent | 41fbca10f6c6cdd9c1623f1347e7ecb40f5e7f59 (diff) | |
| download | meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.tar.zst meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.zip | |
Use own size types
Diffstat (limited to 'src/Math/Random.cpp')
| -rw-r--r-- | src/Math/Random.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/Math/Random.cpp b/src/Math/Random.cpp index aa0ff55..cf3bbad 100644 --- a/src/Math/Random.cpp +++ b/src/Math/Random.cpp @@ -2,10 +2,8 @@ namespace Math::Random { -std::array<uint8_t, 4> break_float(const float f) { - static_assert(sizeof(float) == 4); - - union { float f; uint8_t u[4]; } t{}; +std::array<U8, 4> break_float(const F32 f) { + union { F32 f; U8 u[4]; } t{}; t.f = f; return { @@ -13,18 +11,18 @@ std::array<uint8_t, 4> break_float(const float f) { }; } -float to_float(uint8_t u) { - return (float)u / (float)255; +F32 to_float(U8 u) { + return (F32)u / (F32)255; } -uint8_t hash(uint8_t x) { +U8 hash(U8 x) { auto o = (x ^ 0xAA) * 5; auto rot = o % 8; return o << rot | o >> (8 - rot); } -float random() { - uint8_t r = std::rand() % 255; +Real random() { + U8 r = std::rand() % 255; return to_float(hash(r)); } |
