NO

Author Topic: Random numbers generator issue  (Read 3709 times)

LW

  • Guest
Random numbers generator issue
« on: June 04, 2010, 08:33:01 AM »
Hello. Recently I've found one oddity about Pelles C random numbers generator. Here's the test code:
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
        int i;
srand(time(NULL));

for (i = 0; i < 10; ++i)
printf("%u\n", rand() % 2);

return 0;
}

Besides Pelles C, I tried it on MSVS 2008, MinGW 4.4.0, Borland 5.5 cmd line tools and Tiny C compiler.

What I noticed is that Pelles C, unlike other compilers, tends to generate an output of all 1's with a frightening frequency. So I was unable to make it produce a valid 50/50 chance this way, and was forced to use (rand() % 100) < 50 instead. I personally count it as a significant bug.
« Last Edit: June 04, 2010, 12:42:54 PM by LW »