diff options
Diffstat (limited to 'contrib/syslinux-4.02/gpxe/src/core/random.c')
-rw-r--r-- | contrib/syslinux-4.02/gpxe/src/core/random.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/contrib/syslinux-4.02/gpxe/src/core/random.c b/contrib/syslinux-4.02/gpxe/src/core/random.c new file mode 100644 index 0000000..6e7374e --- /dev/null +++ b/contrib/syslinux-4.02/gpxe/src/core/random.c @@ -0,0 +1,41 @@ +/** @file + * + * Random number generation + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +#include <stdlib.h> +#include <gpxe/timer.h> + +static int32_t rnd_seed = 0; + +/** + * Seed the pseudo-random number generator + * + * @v seed Seed value + */ +void srandom ( unsigned int seed ) { + rnd_seed = seed; +} + +/** + * Generate a pseudo-random number between 0 and 2147483647L or 2147483562? + * + * @ret rand Pseudo-random number + */ +long int random ( void ) { + int32_t q; + + if ( ! rnd_seed ) /* Initialize linear congruential generator */ + srandom ( currticks() ); + + /* simplified version of the LCG given in Bruce Schneier's + "Applied Cryptography" */ + q = ( rnd_seed / 53668 ); + rnd_seed = ( 40014 * ( rnd_seed - 53668 * q ) - 12211 * q ); + if ( rnd_seed < 0 ) + rnd_seed += 2147483563L; + return rnd_seed; +} |