[9661] in Athena Bugs

home help back first fref pref prev next nref lref last post

decmips 7.4G random

daemon@ATHENA.MIT.EDU (epeisach@Athena.MIT.EDU)
Sun Jul 19 16:21:34 1992

From: epeisach@Athena.MIT.EDU
Date: Sun, 19 Jul 92 16:21:26 -0400
To: apk@Athena.MIT.EDU
Cc: bugs@Athena.MIT.EDU
In-Reply-To: [9660]


I believ you are in error in your bug report as my tests indicate that
random is ok. I was able to reproduce a failure mode which is similar to
what you described. (Without seeing your code I cannot be certain...
Your bug reboprt makes no mention of calling initstate, but I suspect
you do...


My testing show that you are wrong as the following demonstrates:


Script started on Sun Jul 19 16:00:42 1992
kangaroo% cat foo.c
main()
{
        int i;
        for(i=0;i<40;i++)
        printf("%d ", random()&01);
}
kangaroo% cc foo.c
kangaroo% a.out
1 0 1 0 1 1 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 1 0 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 0 0
------------------------------------------------------------
Note however if you ever use initstate with the third argument from 8 to
32.... you are using the equivalent of rand.

Script started on Sun Jul 19 16:13:00 1992
kangaroo% cat /tmp/foo.c
main()
{
        int i;
        initstate(1, "abcdefghijklmnop", 12);
        for(i=0;i<40;i++)
        printf("%d ", random()&01);
}
kangaroo% cc foo.c
kangaroo% a.out
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 kangaroo% 

script done on Sun Jul 19 16:13:22 1992
----------------------------------------------------------------------
One drawback about random is that it is the same every time you run it.
The following is a simple modification:

Script started on Sun Jul 19 16:15:38 1992
kangaroo% cat foo.c
main()
{
        int i;
        srandom(time(0));
        for(i=0;i<40;i++)
        printf("%d ", random()&01);
}
kangaroo% cc foo.c
kangaroo% 
kangaroo% a.out
0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 0 0 0 0 0 0 1 kangaroo% 
kangaroo% a.out
0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 0 1 0 1 1 0 1 0 0 kangaroo% 
kangaroo% a.out
1 1 0 1 0 1 1 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 1 kangaroo% 

script done on Sun Jul 19 16:16:24 1992

home help back first fref pref prev next nref lref last post