Mail Archives: djgpp/1994/11/02/10:21:27
Csizmadia Peter <cspt AT ludens DOT elte DOT hu> 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
_________________________________________________________
- Raw text -