Why does rand () on 64 bit RHEL 5 gives different result?
Issue
-
rand ()in RHEL 6 and RHEL 5 64 bit produces different results. -
For following code
#include <stdio.h>
#include <stdlib.h>
int main ()
{
unsigned int nSeed = 2147483648; // or any number bigger than this
printf ("Seed: %d\n", nSeed);
srand (nSeed);
printf ("Random number: %d\n", rand());
return 0;
}
- On RHEL5 and RHEL6 the above gives different results for the random number.
RHEL6 32 and 64 bit:
Seed: -2147483648
Random number: 1336741213
RHEL5 32 bit:
Seed: -2147483648
Random number: 1336741213
RHEL5 64 bit:
Seed: -2147483648
Random number: 722473798
- If the seed is < 2^31, then they produced the same result.
Environment
- Red Hat Enterprise Linux 6
- Red Hat Enterprise Linux 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
