A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Random.hh
1#pragma once
2
4
5#include <Common.hh>
6
7namespace System {
8
9class Random {
10public:
11 Random(u32 seed) : m_x(seed), m_seed(seed) {}
12
13 ~Random() = default;
14
15 void next() {
16 m_x = A * m_x + C;
17 }
18
19 [[nodiscard]] u32 getU32() {
20 next();
21 return static_cast<u32>(m_x >> 0x20);
22 }
23
24 [[nodiscard]] u32 getU32(u32 range) {
25 next();
26 return ((m_x >> 0x20) * range) >> 0x20;
27 }
28
29 [[nodiscard]] f32 getF32() {
30 return MUL * static_cast<f32>(getU32());
31 }
32
33 [[nodiscard]] f32 getF32(f32 range) {
34 return range * getF32();
35 }
36
37private:
38 u64 m_x;
39 u64 m_seed;
40
41 static constexpr u64 A = 0x690379B2B2E3D431;
42 static constexpr u32 C = 0x508EBD;
43 static constexpr f32 MUL = 1.0f / 4294967296.0f; // 1 / (2 ^ 32)
44};
45
46} // namespace System
This header houses common data types such as our integral types and enums.
High-level handling for generic system operations, such as input reading, race configuration,...
Definition CourseMap.cc:5