Mail Archives: djgpp/1994/11/03/03:30:49
How about the function random, let me cite the man page on SunOS
DESCRIPTION
random() uses a non-linear additive feedback random number
generator employing a default table of size 31 long integers
to return successive pseudo-random numbers in the range from
0 to (2**31)-1. The period of this random number generator
is very large, approximately 16*((2**31)-1).
random/srandom have (almost) the same calling sequence and
initialization properties as rand/srand. The difference is
that rand(3V) produces a much less random sequence - in
fact, the low dozen bits generated by rand go through a
cyclic pattern. All the bits generated by random() are
usable. For example,
random()&01
will produce a random binary value.
......
Here is my little test program
main(int argc, char **argv)
{
int i;
srandom(atoi(argv[1]));
for(i=0; i<30; ++i)
printf(" %d", random()&3);
putchar('\n');
}
Here is the results on Sun
2 rice% a.out 7
0 0 0 0 1 2 0 1 0 3 0 2 2 2 0 1 2 1 1 1 3 1 0 0 1 1 0 0 0 1
3 rice% a.out 1
1 2 3 2 3 1 2 3 3 2 3 3 1 0 3 3 3 2 0 2 0 1 2 0 3 1 1 3 2 3
4 rice% a.out 3
2 0 2 0 1 0 0 1 2 1 2 0 0 2 2 1 0 3 3 3 1 1 0 0 1 1 2 2 0 1
And here is the result on Linux
/tmp$ a.out 7
0 2 2 0 3 2 0 3 0 1 2 0 0 0 2 3 2 3 3 3 3 1 2 0 1 1 2 0 2 3
/tmp$ a.out 1
1 0 1 2 1 1 2 1 3 0 1 1 3 2 1 1 3 0 2 0 0 1 0 0 3 1 3 3 0 1
/tmp$ a.out 3
2 2 0 0 3 0 0 3 2 3 0 2 2 0 0 3 0 1 1 1 1 1 2 0 1 1 0 2 2 3
I think the results are pretty good, why not just add "random" and its
friends to go32's C library.
--
Dong Liu <dliu AT ace DOT njit DOT edu>
Electrical and Computer Engineering Department
New Jersey Institute of Technology, Newark, NJ 07102
- Raw text -