NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
c_random.hpp
1#pragma once
2#include <types.h>
3
4/// @brief Random number generation helper class.
5/// @ingroup clib
6/// @unofficial
7class cM_rand_c {
8public:
9
10 /// @brief Initializes the class with the given seed.
11 cM_rand_c(u32 seed) : mSeed(seed) {}
12
13 u32 ranqd1(u32 max); ///< Generates an integer between 0 and the given max.
14 float ranqd2(); ///< Generates a floating point number between 0 and 1.
15 float ranqd3(); ///< Generates a floating point number between -0.5 and 0.5.
16
17 u32 mSeed; ///< The current seed.
18
19private:
20 /// @brief Implementation of the @p ranqd1 algorithm.
21 /// @bug The implementation is flawed.
22 /// @xlink{https://roadrunnerwmc.github.io/blog/2020/05/08/nsmb-rng.html, This post explains why}.
23 inline u32 ranqdStep();
24
25 static u32 mConst1; ///< Constant @p a from the @p ranqd1 algorithm.
26 static u32 mConst2; ///< Constant @p c from the @p ranqd1 algorithm.
27};
u32 ranqdStep()
Implementation of the ranqd1 algorithm.
Definition c_random.cpp:9
u32 mSeed
The current seed.
Definition c_random.hpp:17
cM_rand_c(u32 seed)
Initializes the class with the given seed.
Definition c_random.hpp:11
float ranqd3()
Generates a floating point number between -0.5 and 0.5.
Definition c_random.cpp:39
u32 ranqd1(u32 max)
Generates an integer between 0 and the given max.
Definition c_random.cpp:28
static u32 mConst1
Constant a from the ranqd1 algorithm.
Definition c_random.hpp:25
static u32 mConst2
Constant c from the ranqd1 algorithm.
Definition c_random.hpp:26
float ranqd2()
Generates a floating point number between 0 and 1.
Definition c_random.cpp:33