fixed bad state parameter type
This commit is contained in:
parent
563ec5eedd
commit
bd6c1e2b18
@ -24,13 +24,13 @@ static inline rand_state init_rand() {
|
|||||||
#endif /* NO_CSTDLIB */
|
#endif /* NO_CSTDLIB */
|
||||||
|
|
||||||
// 32-bit LCG
|
// 32-bit LCG
|
||||||
static inline uint32_t lcg(uint32_t *state) {
|
static inline uint32_t lcg(rand_state *state) {
|
||||||
*state = *state * 1664525u + 1013904223u;
|
*state = *state * 1664525u + 1013904223u;
|
||||||
return *state;
|
return *state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Pick a "reasonably random" number in [0, until-1] without modulus */
|
/** Pick a "reasonably random" number in [0, until-1] without modulus */
|
||||||
static inline uint32_t rand_until(uint32_t *state, uint32_t until) {
|
static inline uint32_t rand_until(rand_state *state, uint32_t until) {
|
||||||
uint32_t rand = lcg(state);
|
uint32_t rand = lcg(state);
|
||||||
// Multiply by "until", take the upper 32 bits of the 64-bit result
|
// Multiply by "until", take the upper 32 bits of the 64-bit result
|
||||||
return (uint32_t)(((uint64_t)rand * until) >> 32);
|
return (uint32_t)(((uint64_t)rand * until) >> 32);
|
||||||
@ -44,7 +44,7 @@ static inline uint32_t rand_until(uint32_t *state, uint32_t until) {
|
|||||||
* @param to The biggest possible value + 1
|
* @param to The biggest possible value + 1
|
||||||
* @returns A value in [from, to) interval
|
* @returns A value in [from, to) interval
|
||||||
*/
|
*/
|
||||||
static inline uint32_t rand_between(uint32_t *state, uint32_t from, uint32_t to) {
|
static inline uint32_t rand_between(rand_state *state, uint32_t from, uint32_t to) {
|
||||||
return from + rand_until(state, to - from);
|
return from + rand_until(state, to - from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user