any good methods for generating psuedo random numbers
Quote:
> The following is a transcription in C from
> "Practical algorithms in C++" by Bryan Flamig:
My favourite for both elegance and period is from Bruce Schneier's
_Applied Cryptography (2nd Ed.)_
static long s1 = 1; /* A "long" must be 32 bits long */
static long s2 = 1;
#define MODMULT(a,b,c,m,s) q = s/a; s = b*(s-a*q) - c*q; if (s<0) s+=m
/* MODMULT(a,b,c,m,s) computes s*b mod m, provided that m=a*b+c and
0<=c<m */
/*
* combinedLCG returns a pseudorandom real value in the range
* (0,1). It combines linear congruential generators with
* periods of 2^31-85 and 2^31-249, and has a period that is
* the product of these two prime numbers
*/
double combinedLCG (void)
{
long q ;
long z ;
MODMULT (53668, 40014, 12211, 2147483563L, s1);
MODMULT (52774, 40692, 3791, 2147483399L, s2);
z = s1 - s2 ;
if (z < 1 )
z += 2147483562 ;
return z * 4.656613e-10 ;
Quote:
}
void initLCG ( long InitS1, long InitS2 )
{
s1 = InitS1 ;
s2 = InitS2 ;
Quote:
}
"This generator works as long as the machine can represent all integers
between -2^31+85 and 2^31-85. The variables s1 and s2 are global; they
hold the current state of the generator. Before the first call they
must be initialised. The variable s1 needs an initial value between
2147483562; the variable s2 needs an initial value between 1 and
2147483398. The generator has a period somewhere in the neighborhood of
10^18."
--
The above may or may not represent my own views. It quite probably
does not represent the views of HP.
--