blob: e35cda73864d9a41fb26a1c6c10bb7a4702c2730 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include "Random.hpp"
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{};
t.f = f;
return {
t.u[0], t.u[1], t.u[2], t.u[3]
};
}
float to_float(uint8_t u) {
return (float)u / (float)255;
}
uint8_t hash(uint8_t x) {
auto o = ((x ^ 0xAA) * 5);
auto rot = o % 8;
return o << rot | o >> (8 - rot);
}
float random() {
uint8_t r = std::rand() % 255;
return to_float(hash(r));
}
}
|