Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Random Number generation in C/C++

22 views
Skip to first unread message

Ramin Sina

unread,
Feb 28, 2001, 9:49:25 AM2/28/01
to
Hi all,

I was wondering if anyone knows what is the peridocity of rand() system
function that is included in standard C/C++ for Red Hard 6.2 gnu C++
compiler on intel machine

I was also wondering is anyone knows of a better (reliable, slow is OK)
C/C++ generator code freely available to produce few hundred million
numbers.

Thanks very much.
Cheers,

Ramin Sina

Dann Corbit

unread,
Feb 28, 2001, 1:16:23 PM2/28/01
to
"Ramin Sina" <rsina_no...@earthlink.net> wrote in message
news:Vd8n6.1829$%4.21...@newsread1.prod.itd.earthlink.net...

> Hi all,
>
> I was wondering if anyone knows what is the peridocity of rand() system
> function that is included in standard C/C++ for Red Hard 6.2 gnu C++
> compiler on intel machine
>
> I was also wondering is anyone knows of a better (reliable, slow is OK)
> C/C++ generator code freely available to produce few hundred million
> numbers.


http://www.math.keio.ac.jp/~matumoto/emt.html
--
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
"The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm


Thomas Holenstein

unread,
Feb 28, 2001, 2:10:05 PM2/28/01
to
> I was also wondering is anyone knows of a better (reliable, slow is OK)
> C/C++ generator code freely available to produce few hundred million
> numbers.

Take also a look at
www.boost.org

I do not know if it is good to produce millions of numbers, but it is
well documented and you will find the information you need.

Thomas

Roy A. Fletcher

unread,
Mar 1, 2001, 2:28:04 AM3/1/01
to
Ramin Sina (rsina_no...@earthlink.net) wrote:
with editing...
: I was wondering if anyone knows what is the peridocity of rand() system
: function that is included in standard C/C++ for Red Hard 6.2 gnu C++
: compiler on intel machine

: I was also wondering is anyone knows of a better (reliable, slow is OK)
: C/C++ generator code freely available to produce few hundred million
: numbers.

I use APL for this.
The deal (?) operator will produce as many as you wish, and it is not
slow. The random nos. can be stored in an n-dim vector.
One million nos. occupy about 8 meg.
I saw a rating of random no. generators some while ago, and the function
in APL2 got a mid-to-high rating. I'm sure other APLs are very similar.

Regards. RAF

George Marsaglia

unread,
Mar 1, 2001, 5:41:24 PM3/1/01
to

Ramin Sina wrote:

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);
}
--------------------------------------------------------------
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 MWC1029 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


Rupert Mazzucco

unread,
Mar 2, 2001, 2:32:08 PM3/2/01
to
George Marsaglia schrieb:

> Try this, one of my latest RNG's:

> [...]

Oh, this one looks cool! It really pays off to follow
your postings here in smna. :^)

Regards,
Rupert Mazzucco
--
Of all the things I´ve lost ... I miss my pants the most.
--Michael Poe

Vince Castelli

unread,
Mar 4, 2001, 9:16:43 AM3/4/01
to
Hi Prof. Marsaglia!

Where can I get a copy of tuftsts.c?


George Marsaglia wrote:
>
> Ramin Sina wrote:
>
> ? Hi all,
> ?
> ? I was wondering if anyone knows what is the peridocity of rand() system
> ? function that is included in standard C/C++ for Red Hard 6.2 gnu C++
> ? compiler on intel machine
> ?
> ? I was also wondering is anyone knows of a better (reliable, slow is OK)
> ? C/C++ generator code freely available to produce few hundred million
> ? numbers.


>
> 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);

George Marsaglia

unread,
Mar 6, 2001, 7:28:19 AM3/6/01
to

Vince Castelli wrote:

> Hi Prof. Marsaglia!
> Where can I get a copy of tuftsts.c?

I have not yet published a description of the three tests in tuftsts.c, but
will send a listing to requesters who identify themselves with who and why.

In turn, I request feedback on results.

tuftsts.c calls the RNG as needed, expecting a 32-bit unsigned long,
which is identified by putting the name of your RNG procedure
in a define statement:

#define IUNI yourrng( )

The tests take a long time, particularly the Gorilla Test, which tests
each one of the 32 bits, calling it 61 million times.

I have found that RNG's that fail some of the Diehard battery of tests
will fail one or more of the three tough tests, and conversely, a RNG
that passes tuftsts.c seems to pass all the tests in Diehard.

George Marsaglia

0 new messages