in search of a good random number generator
Posted: Wed May 05, 2004 8:44 am
i been searching the web for a good random number generator, i found one by Paul Dixon. http://www.masmforum.com/viewtopic.php?t=2740
i dapted it to PellesC, but need some help since i am still a C neophyte.
how can i optionally set the static variable rng? (to seed the rnd generator)
i dapted it to PellesC, but need some help since i am still a C neophyte.
how can i optionally set the static variable rng? (to seed the rnd generator)
Code: Select all
double random(void)
{ static long long int rng=0x1954678542154787;
int result;
long long int mask2=0x7fffffffffffffff;
_asm{
movq mm0,rng; //get the last number
movq mm1,mm0;
psllq mm0,1;
pxor mm1,mm0;
pand mm1,mask2;
movq mm0,mm1;
psrlq mm1,62;
pxor mm0,mm1;
movq rng,mm0;
emms; //re-enable FPU
}
return frexp((double) rng,&result); //result between 0 and 1
}