Re: question on rand()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/06/2011 08:47 AM, Anna Sidera wrote:
> Hello,
> 
> I am using gcc on a unix machine. Can you tell me how many random numbers can be generated using
> 
> rand()
> 
> before the random numbers start repeating? I found that RAND_MAX is equal to 2147483647.

One would hope it has full period, i.e. it generates all RAND_MAX numbers,
but that depends on your system.

It's perhaps not a good idea to depend on the system's generator.  A decent
32-bit one is

unsigned int xor-generator()
{
   static unsigned int y=2463534242;
   y^=(y<<13); y^=(y>>17); return (y^=(y<<5));
}

Andrew.

http://www.jstatsoft.org/v08/i14/paper


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux