david/ipxe
Archived
1
0
This repository has been archived on 2020-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
ipxe/src/core/random.c
Michael Brown 8406115834 [build] Rename gPXE to iPXE
Access to the gpxe.org and etherboot.org domains and associated
resources has been revoked by the registrant of the domain.  Work
around this problem by renaming project from gPXE to iPXE, and
updating URLs to match.

Also update README, LOG and COPYRIGHTS to remove obsolete information.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-04-19 23:43:39 +01:00

42 lines
795 B
C

/** @file
*
* Random number generation
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdlib.h>
#include <ipxe/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;
}