Bug 1301913

Summary: Incorrect rand() result when seed >=2^31
Product: Red Hat Enterprise Linux 5 Reporter: Piyush Bhoot <pbhoot>
Component: glibcAssignee: Carlos O'Donell <codonell>
Status: CLOSED WONTFIX QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: unspecified    
Version: 5.11CC: ashankar, fweimer, mnewsome, pbhoot, pfrankli, rzaleski
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-02-01 17:22:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Piyush Bhoot 2016-01-26 11:20:27 UTC
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:
1.

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

/usr/src/debug/glibc-2.12-2-gc4ccff1/stdlib/random_r.c

    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 12:13:30 UTC
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 Program Management 2016-01-29 12:22:46 UTC
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 17:17:00 UTC
Hi,

Thanks for details, this addresses customer concern.

We good to close the bug.

Best Regards,
Piyush

Comment 4 Carlos O'Donell 2016-02-01 17:22:42 UTC
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.