[efi] Include installed protocol list in unknown handle names
[ipxe.git] / src / core / random.c
1 /** @file
2 *
3 * Random number generation
4 *
5 */
6
7 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
8
9 #include <stdlib.h>
10 #include <ipxe/timer.h>
11
12 static int32_t rnd_seed = 0;
13
14 /**
15 * Seed the pseudo-random number generator
16 *
17 * @v seed Seed value
18 */
19 void srandom ( unsigned int seed ) {
20 rnd_seed = seed;
21 }
22
23 /**
24 * Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
25 *
26 * @ret rand Pseudo-random number
27 */
28 long int random ( void ) {
29 int32_t q;
30
31 if ( ! rnd_seed ) /* Initialize linear congruential generator */
32 srandom ( currticks() );
33
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 );
38 if ( rnd_seed < 0 )
39 rnd_seed += 2147483563L;
40 return rnd_seed;
41 }