rand() function performs poorly
William M. Grim
wgrim at siue.edu
Tue May 11 23:37:37 PDT 2004
Hello!
It came to my attention during a test of the rand() function on
DragonFly that the rand() function performs poorly.
Take this code for example:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int cs, i,r; /*cs == case*/
srand(time(0));
while(1)
{
cs = rand() % 2;
if(cs)
printf("O");
else
printf("o");
fflush(stdout);
}
return EXIT_SUCCESS;
}
When you run that code, it will print "OoOoOoOo..." without any change;
it's very predictable.
I'm certainly up for bringing the later 4.x rand() code down into
DragonFly. Where do you think they keep it?
And don't one of you other peeps go and do it for me. :-D I want to try
this one on my own! >:-)
Thanks,
Mike
More information about the Kernel
mailing list