ГЕНЕРАТОР СЛУЧАЙНЫХ ЧИСЕЛ
- From
- Max Alekseyev (2:5015/60)
- To
- Dmitry Grusdev
- Date
- 2002-10-08T15:12:18Z
- Area
- RU.ALGORITHMS
████ OS/2 Hi, Dmitry !
Replying to a message of Dmitry Grusdev to All:
DG> Народ, может у кого есть генератор случайных чисел с большим периодом?
Mersenne Twister имеет период 2^19937-1
http://www.math.keio.ac.jp/~matumoto/emt.html
А вот еще один от George Marsaglia с периодом более 10^9824:
===cut===
/*
George Marsaglia writes:
"Try this, one of my latest RNG's:
-------------------------------------------------------
*/
static unsigned long Q[1019];
unsigned long MWC1019(void)
{unsigned long long t;
static unsigned long c = 362436, i = 1018;
t = 147669672LL*Q[i] + c; c = (t>>32);
if(i>0) return(Q[i--] = t);
i = 1018; return(Q[0] = t);
}
unsigned long MWC1019(unsigned long m)
{
return MWC1019() % m;
}
/*
-------------------------------------------------------
It will provide random 32-bit integers at the rate of 300 million per
second (on a 850MHz PC).
It requires that you seed Q[0],Q[1],...Q[1018] with 32-bit random
integers, before calling MWC1019( ) in your main. You might use a
good RNG such as KISS to fill the Q array.
The period of MWC1019 exceeds 10^9824, making it billions and
billions ... and billions times as long as the highly touted
longest-period RNG, the Mersenne twister. It is also several times
as fast and takes a few lines rather than several pages of code.
(This is not to say that the Mersenne twister is not a good RNG; it
is. I just do not equate complexity of code with randomness. It is
the complexity of the underlying randomness that counts.)
As for randomness, it passes all tests in The Diehard Battery of
Tests of Randomness
http://stat.fsu.edu/pub/diehard as well as three new tough tests I have developed with the apparent
property that a RNG that passes tuftsts.c will pass all the tests in
Diehard.
MWC1019 has the property that every possible sequence of 1018
successive 32-bit integers will appear somewhere in the full period,
for those concerned with the "equi-distribution" in dimensions
2,3,...1016,1017,1018.
I welcome comments on timings or otherwise.
George Marsaglia"
*/
===cut===
Regards, °°
Max ~
--- FleetStreet 1.27.3.8
* Origin: (2:5015/60)