Bug 1301913 - Incorrect rand() result when seed >=2^31
Incorrect rand() result when seed >=2^31
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: glibc (Show other bugs)
x86_64 Linux
unspecified Severity medium
: rc
: ---
Assigned To: Carlos O'Donell
Depends On:
  Show dependency treegraph
Reported: 2016-01-26 06:20 EST by Piyush Bhoot
Modified: 2016-02-01 12:22 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2016-02-01 12:22:42 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Piyush Bhoot 2016-01-26 06:20:27 EST
Description of problem:
RHEL5 and RHEL6 generates different rand() result with same seed when the seed >=2^31

This issue is particular to RHEL 5 64 bit

Version-Release number of selected component (if applicable):

How reproducible:Always

Steps to Reproduce:

With below 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;

Actual results:

Seed: -2147483648
Random number: 1336741213

Expected results:

Seed -2147483648
Random number: 722473798

Additional info:

For RHEL 6 This issue was fixed in upstream[1] [2] by turning long int to int32_t


    struct random_data *buf;
  int type;
  int32_t *state;
  long int i;
  int32_t word;
  int32_t *dst;
  int kc;

[1]Bugzilla @ https://sourceware.org/bugzilla/show_bug.cgi?id=9920
[2]Bug fix @ https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=fe12c7984b6631cf5e7b66d97f51f4aa16fd821e
Comment 1 Florian Weimer 2016-01-26 07:13:30 EST
It seems to me that the upstream change you identified was made to bring 32-bit and 64-bit platforms in line, giving both them the same sequence with the same seed.  This means that the behavior in Red Hat Enterprise Linux 6 is more correct than the previous behavior in Red Hat Enterprise Linux 5.

We do not want to change Red Hat Enterprise Linux 5 at this point because other customers could expect that rand keeps generating the same number sequence from the same seed, even after a glibc upgrade within the same major release of Red Hat Enterprise Linux 5.

Please let us know if this addresses your concerns.
Comment 2 RHEL Product and Program Management 2016-01-29 07:22:46 EST
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.
Comment 3 Piyush Bhoot 2016-02-01 12:17:00 EST

Thanks for details, this addresses customer concern.

We good to close the bug.

Best Regards,
Comment 4 Carlos O'Donell 2016-02-01 12:22:42 EST
Given that we're not going to fix this for RHEL5 I'm marking this CLOSED/WONTFIX. Please open another bug if you have any more questions.

Note You need to log in before you can comment on or make changes to this bug.