8 #elif defined HOST_LINUX
19 #define INITIAL_SEED 327680
26 static double hRnd_QB (
float n );
56 return (
double)rand( ) * ( 1.0 / ( (double)RAND_MAX + 1.0 ) );
66 return (
double)
iseed / (double)4294967296ULL;
74 uint32_t i, v, xor_mask[2] = { 0, 0x9908B0DF };
84 v = (
state[i] & 0x80000000 ) | (
state[i + 1] & 0x7FFFFFFF );
88 v = (
state[i] & 0x80000000 ) | (
state[i + 1] & 0x7FFFFFFF );
91 v = (
state[MAX_STATE - 1] & 0x80000000 ) | (
state[0] & 0x7FFFFFFF );
92 state[MAX_STATE - 1] =
state[PERIOD - 1] ^ ( v >> 1 ) ^ xor_mask[v & 0x1];
98 v ^= ( ( v << 7 ) & 0x9D2C5680 );
99 v ^= ( ( v << 15 ) & 0xEFC60000 );
102 return (
double)v / (double)4294967296ULL;
116 iseed = s + ( s >> 24 );
118 iseed = ( (
iseed * 0xFD43FD ) + 0xC39EC3 ) & 0xFFFFFF;
120 return (
float)
iseed / (float)0x1000000;
123 #if defined HOST_WIN32 || defined HOST_LINUX
124 static unsigned int hGetRealRndNumber( )
128 unsigned char b[
sizeof(
unsigned int)];
131 #if defined HOST_WIN32
132 HCRYPTPROV provider = 0;
133 if( CryptAcquireContext( &provider,
NULL, 0, PROV_RSA_FULL, 0 ) ==
TRUE ) {
134 if( CryptGenRandom( provider,
sizeof(number), &number.b[0] ) ==
FALSE ) {
137 CryptReleaseContext( provider, 0 );
140 #elif defined HOST_LINUX
141 int urandom = open(
"/dev/urandom", O_RDONLY );
142 if( urandom != -1 ) {
143 if( read( urandom, &number.b[0],
sizeof(number) ) !=
sizeof(number) ) {
153 static double hRnd_REAL(
float n )
155 static unsigned int count = 0;
156 static unsigned int v;
160 if( (count % 256) == 0 ) {
164 v = hGetRealRndNumber( );
175 v ^= ((v << 7) & 0x9D2C5680);
176 v ^= ((v << 15) & 0xEFC60000);
179 return (
double)v / (double)4294967296ULL;
215 seed = (double)(dtoi.i[0] ^ dtoi.i[1]);
218 switch( algorithm ) {
221 srand( (
unsigned int)seed );
227 iseed = (uint32_t)seed;
233 uint32_t s = dtoi.i[1];
235 s = ( ( s & 0xFFFF ) << 8 ) | (
iseed & 0xFF );
239 #if defined HOST_WIN32 || defined HOST_LINUX
242 state[0] = (
unsigned int)seed;
244 state[i] = (
state[i - 1] * 1664525 ) + 1013904223;
252 state[0] = (
unsigned int)seed;
254 state[i] = (
state[i - 1] * 1664525 ) + 1013904223;