Mail Archives: djgpp-workers/2000/06/08/19:50:52
Could those of you with random number generator testers compare these
generators? The first is from DJGPP, and the other two are from
newlib.
#define RAND_MAX 0x7fffffff
unsigned
rand1()
{
static unsigned long long next = 1;
next = next * 6364136223846793005LL + 1;
return (int)((next >> 21) & RAND_MAX);
}
unsigned
rand2()
{
long k;
static long s = 1;
if (s == 0)
s = 0x12345987;
k = s / 127773;
s = 16807 * (s - k * 127773) - 2836 * k;
if (s < 0)
s += 2147483647;
return (int)(s & RAND_MAX);
}
unsigned
rand3()
{
static unsigned int next = 1;
return ((next = next * 1103515245 + 12345 ) & RAND_MAX );
}
main()
{
int i;
for (i=0; i<20; i++)
printf("%15d %15d %15d\n", rand1(), rand2(), rand3());
}
- Raw text -