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