Date: Wed, 2 Nov 1994 12:43:46 +0000 To: djgpp AT sun DOT soe DOT clarkson DOT edu From: alan DOT macdonald AT brunel DOT ac DOT uk (Alan MacDonald) Subject: Re: Is it random number sequence? Csizmadia Peter said >int main(int argc, char* argv[]) >{ > int i; > srand(atoi(argv[1])); > for(i=0; i<30; ++i) > printf(" %d", rand()&3); > putchar('\n'); >} > This simple program produces the following "random number sequence" >for any seed number: > 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 > > Is it the normal behavior of the rand() function in GNU C? this is normal behaviour for linear congruential generators - the low bits have short periods (2**bits). You'll get a better sequence if you mask out some high bits & shift right. --------------------------------------------------------- Alan DOT MacDonald AT brunel DOT ac DOT uk, +44 895 274000 x2323 Elec Eng, Brunel University, Uxbridge, MIDDX, UB8 3PH, UK _________________________________________________________