3 * Random number generation
7 FILE_LICENCE ( GPL2_OR_LATER
);
10 #include <gpxe/timer.h>
12 static int32_t rnd_seed
= 0;
15 * Seed the pseudo-random number generator
19 void srandom ( unsigned int seed
) {
24 * Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
26 * @ret rand Pseudo-random number
28 long int random ( void ) {
31 if ( ! rnd_seed
) /* Initialize linear congruential generator */
32 srandom ( currticks() );
34 /* simplified version of the LCG given in Bruce Schneier's
35 "Applied Cryptography" */
36 q
= ( rnd_seed
/ 53668 );
37 rnd_seed
= ( 40014 * ( rnd_seed
- 53668 * q
) - 12211 * q
);
39 rnd_seed
+= 2147483563L;