NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
c_random.cpp
Go to the documentation of this file.
1#include <types.h>
2#include <game/cLib/c_random.hpp>
3/// @file
4
5/// @ingroup clib
6namespace cRandom {
7 u32 l_RANDOM_MUL = 0x19660D; ///< Constant @p a from the @p ranqd1 algorithm.
8 u32 l_RANDOM_ADD = 0x3C6EF35F; ///< Constant @p c from the @p ranqd1 algorithm.
9}
10
11// This decompiled terribly but at least it matches
12// Original algorithm: https://s3.amazonaws.com/nrbook.com/book_C210_pdf/chap07c.pdf (page 284-285)
14
15 // Variables must be declared in this order or there will be regswaps
16 register u32 c, b, a, x;
17 x = mSeed;
20
21 // Longlong math needs to be done in asm in order to match...
22 asm {
23 mulhwu c, x, a
24 mullw x, x, a
25 addc x, x, b
26 adde x, x, c
27 }
28
29 return x;
30}
31
33 mSeed = ranqdStep();
34 return ((u64) mSeed * max) >> 32;
35}
36
38 mSeed = ranqdStep();
39 u32 tmp = 0x3f800000 | (mSeed >> 9 & 0x7fffff);
40 return (*(float *)&tmp)-1.0f;
41}
42
44 mSeed = ranqdStep();
45 u32 tmp = 0x3f800000 | (mSeed >> 9 & 0x7fffff);
46 return (*(float *)&tmp)-1.5f;
47}
u32 l_RANDOM_MUL
Constant a from the ranqd1 algorithm.
Definition c_random.cpp:7
u32 l_RANDOM_ADD
Constant c from the ranqd1 algorithm.
Definition c_random.cpp:8
float getRandomFByAsm()
Generates a floating point number between 0 and 1.
Definition c_random.cpp:37
float getRandomF2ByAsm()
Generates a floating point number between -0.5 and 0.5.
Definition c_random.cpp:43
u32 mSeed
The current seed.
Definition c_random.hpp:16
u32 getRandomByAsm(ulong max)
Generates an integer between 0 and the given max.
Definition c_random.cpp:32
u32 ranqdStep()
Implementation of the ranqd1 algorithm.
Definition c_random.cpp:13