5 * Finds a pseudorandom 32-bit number from 0 to 2^32-1 .
6 * Uses the BCPL linear congruential generator method.
8 * Used instead of system RNG to ensure tests are consistent.
10 static uint32_t rand32(void)
14 * Tests should be run with a different random function
15 * from time to time. I've found that the method below
16 * sometimes behaves poorly for testing purposes.
17 * For example, rand32() % N might only return even numbers.
19 assert(RAND_MAX == 2147483647);
20 return ((random() & 0xFFFF) << 16) | (random() & 0xFFFF);
22 static uint32_t rand32_state = 0;
23 rand32_state *= (uint32_t)0x7FF8A3ED;
24 rand32_state += (uint32_t)0x2AA01D31;