bugAVR C Runtime Library - Bugs: bug #18662, rand() keeps returning the same...

 
 

bug #18662: rand() keeps returning the same value if seeded with 0

Submitted by:  Roland Bluethgen <calocybe>
Submitted on:  Sun 31 Dec 2006 01:57:10 PM UTC  
 
Category: LibrarySeverity: 4 - Important
Priority: 7 - HighItem Group: libc code
Status: FixedPercent Complete: 0%
Assigned to: Joerg Wunsch <joerg_wunsch>Open/Closed: Closed
Release: NoneFixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 08 Jan 2007 02:10:19 PM UTC, comment #1:

This is an issue with the original BSD implementation our
implementation has been taken from. See here for the
FreeBSD fix:

http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdlib/random.c?f=h#rev1.21

Joerg Wunsch <joerg_wunsch>
Project AdministratorIn charge of this item.
Sun 31 Dec 2006 01:57:10 PM UTC, original submission:

The function do_rand() in rand.c, invoked by rand(), keeps returning the same value, in particular RAND_MAX, if the static variable 'next' is seeded with srand(0).

The algorithm in do_rand() calculates a new value for ctx from the current value of ctx.
If *ctx == 0, the new value calculated will be 0x7fffffffL.
If *ctx == 0x7fffffffL, the new value calculated will be 0x7fffffffL again.
Thus, the return value will be always the same.

This does most probably apply to random() in an analogous manner as the code in do_random() in random.c looks very much the same, only the return value will be RANDOM_MAX, not RAND_MAX.

Roland Bluethgen <calocybe>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by joerg_wunsch (Updated the item)
  • -unavailable- added by calocybe (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 08 Jan 2007 03:11:05 PM UTCjoerg_wunschStatusIn Progress=>Fixed
      Open/ClosedOpen=>Closed
    Mon 08 Jan 2007 02:10:19 PM UTCjoerg_wunschStatusConfirmed=>In Progress
    Mon 08 Jan 2007 12:57:19 PM UTCjoerg_wunschItem GroupNone=>libc code
    Mon 08 Jan 2007 12:37:53 PM UTCjoerg_wunschSeverity3 - Normal=>4 - Important
      Priority5 - Normal=>7 - High
      StatusNone=>Confirmed
      Assigned toNone=>joerg_wunsch

    Back to the top


    Powered by Savane 3.1-cleanup1