question on rand()

Anna Sidera sidera.anna@ucy.ac.cy
Sun Aug 7 08:42:00 GMT 2011


The program I wrote uses 2*10^8 random numbers which are produced using rand. Is there a way to find if rand produces duplicates in my program? I found that RAND_MAX is equal to 2^31-1 in the machine I am using.

Anna

----- Original Message -----
From: Ian Lance Taylor <iant@google.com>
Date: Saturday, August 6, 2011 10:01 pm
Subject: Re: question on rand()

> Anna Sidera <sidera.anna@ucy.ac.cy> writes:
> 
> >>From this, can I find out when the numbers start repeating? How 
> can I find it? I cannot find the period using
> >
> > man rand
> 
> This question really doesn't have anything to do with gcc.  gcc 
> does not
> provide a rand function.  The rand function will come from your C
> library, and gcc does not include a C library.
> 
> If you are using GNU glibc, which is probably the case if you are 
> usinga GNU/Linux system, then rand is not implemented as a linear
> congruential generator, and the period is quite long.  See the source
> code.
> 
> Ian
> 



More information about the Gcc-help mailing list