From fe2baedc760c2f29e2c720f6b1132a2de33c5430 Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 8 Jul 2023 03:25:44 +0200 Subject: Use own size types --- src/Math/Random.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/Math/Random.cpp') 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 break_float(const float f) { - static_assert(sizeof(float) == 4); - - union { float f; uint8_t u[4]; } t{}; +std::array break_float(const F32 f) { + union { F32 f; U8 u[4]; } t{}; t.f = f; return { @@ -13,18 +11,18 @@ std::array 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)); } -- cgit 1.4.1