1 #include <stdint.h> /* uint16_t, uint32_t */
5 /* Pseudo-randomness seed for rrand(), set by seed_rrand(). */
6 static uint32_t seed = 0;
10 /* With set_seed set, set seed global to seed_input. In any case, return it. */
11 extern uint32_t seed_rrand(uint8_t set_seed, uint32_t seed_input)
22 /* Return 16-bit number pseudo-randomly generated via Linear Congruential
23 * Generator algorithm with some proven constants. Use instead of any rand() to
24 * ensure portability of the same pseudo-randomness across systems.
26 extern uint16_t rrand()
27 { /* Constants as recommended by POSIX.1-2001 (see man page rand(3)). */
28 seed = ((seed * 1103515245) + 12345) % 4294967296;
29 return (seed >> 16); /* Ignore less random least significant bits. */