fixed bad state parameter type

This commit is contained in:
Richard Thier 2025-04-01 19:22:46 +02:00
parent 563ec5eedd
commit bd6c1e2b18

View File

@ -24,13 +24,13 @@ static inline rand_state init_rand() {
#endif /* NO_CSTDLIB */
// 32-bit LCG
static inline uint32_t lcg(uint32_t *state) {
static inline uint32_t lcg(rand_state *state) {
*state = *state * 1664525u + 1013904223u;
return *state;
}
/** 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);
// Multiply by "until", take the upper 32 bits of the 64-bit result
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
* @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);
}