question on rand()

Dennis Clarke dclarke@blastwave.org
Sat Aug 6 22:45:00 GMT 2011


> 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 using
> a GNU/Linux system, then rand is not implemented as a linear
> congruential generator, and the period is quite long.  See the source
> code.
>

At risk of being well and truely off topic, I suggest that prng folks look
at the "Mersenne twister" algorithm developed by Makoto Matsumoto and
Takuji Nishimura :

  http://en.wikipedia.org/wiki/Mersenne_twister

Works great.

I think that ends this topic.

-- 
--
+-------------------------+-----------------------------------+
| Dennis Clarke           | Solaris and Linux and Open Source |
| dclarke@blastwave.org   | are my passion. ( FREE == OPEN )  |
+-------------------------+-----------------------------------+




More information about the Gcc-help mailing list