The following program: #include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> #include <string.h> int main() { int i=0; int j=rand(); while (rand()!=j) i++; printf("%d\n",i); return 0; } gives the following output: -1406966551 >From this, can I find out when the numbers start repeating? How can I find it? I cannot find the period using man rand Anna ----- Original Message ----- From: Marc Glisse <marc.glisse@xxxxxxxx> Date: Saturday, August 6, 2011 7:34 pm Subject: Re: question on rand() > On Sat, 6 Aug 2011, Andrew Haley wrote: > > > 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? > > man rand > If it's not there, complain to your unix vendor. > The period is required by posix to be larger or equal to 2^32. > > > One would hope it has full period, i.e. it generates all > RAND_MAX numbers, > > but that depends on your system. > > One would even hope the period is larger, so the output of rand() > is not a > deterministic function of its last return value (random generators > often > keep a hidden state). > > -- > Marc Glisse >