MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Random_Next

Function Random_Next

src/ExtMath.c:132–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132int Random_Next(RNGState* seed, int n) {
133 cc_int64 raw;
134 int bits, val;
135
136 if ((n & -n) == n) { /* i.e., n is a power of 2 */
137 *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
138 raw = (cc_int64)(*seed >> (48 - 31));
139 return (int)((n * raw) >> 31);
140 }
141
142 do {
143 *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
144 bits = (int)(*seed >> (48 - 31));
145 val = bits % n;
146 } while (bits - val + (n - 1) < 0);
147 return val;
148}
149
150float Random_Float(RNGState* seed) {
151 int raw;

Callers 15

Random_RangeFunction · 0.85
Particles_RainSnowEffectFunction · 0.85
ClassicGenScreen_GenFunction · 0.85
GenerateNewUuidFunction · 0.85
Soundboard_PickRandomFunction · 0.85
Music_RunLoopFunction · 0.85
Physics_HandleSaplingFunction · 0.85
NotchyGen_CarveCavesFunction · 0.85
NotchyGen_CarveOreVeinsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected