The random and the rand functions generates the same set of random numbers,
every time the code is executed. Though it would generate 2 different random
numbers if the function was called two times in a same code, if the code is
compiled and executed again, it generates the same set of random numbers.

Here is the sample code to reproduce the bug. 
filename: generateRandom.c

#include <stdio.h>

int main()
{
  long int i, j;
  i = random();
  j = random();
  printf("Random number 1: %ld\n", i);
  printf("Random number 2: %ld\n", j);
  return 0;
}

If this code is executed multiple times the same random numbers are generated.
I have a fix for this problem which I have been using for a while. If this is a
valid bug, I can give a patch for this.

Rahul
rsanghavi At gmail Dot com


-- 
           Summary: Random number generates the same set of numbers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rsanghavi at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34096

Reply via email to