[12727] in Athena Bugs
decmips 7.7G: rand()
daemon@ATHENA.MIT.EDU (Petr Adamek)
Wed Oct 12 18:21:21 1994
To: bugs@MIT.EDU
Date: Wed, 12 Oct 1994 18:21:12 EDT
From: Petr Adamek <adamek@MIT.EDU>
System name: e51-007-12
Type and version: KN02ca 7.7G
Display type: PMAG-DV
What were you trying to do?
To use system random number generator rand(3).
What's wrong:
Resulting numbers can be *hardly* considered (pseudo)random!! Indeed,
they are not. In repeated use of rand(), I have got alternating
sequence of odd and even numbers...
What should have happened:
I should have got some "reasonably" pseudorandom sequence.
Please describe any relevant documentation references:
DOCUMENTATION:
rand(3) manpage
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#define N 75 /* digits per line printed */
#define M 20 /* number of lines */
#define K 2 /* digits */
int
main()
{
int i, j;
srand(1);
for (i = 0; i < M; i++){
for (j = 0; j < N; j++)
printf("%d", rand() % K);
printf("\n");
}
return 0;
}
COMPILE:
add gnu
gcc -ansi -Wall -pedantic filename.c
RUN:
./a.out
OUTPUT:
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101
Sincerely,
Petr