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

 
 

You are not allowed to post comments on this tracker with your current authentication level.

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

Submitter:  Roland Bluethgen <calocybe>
Submitted:  Sun 31 Dec 2006 01:57:10 PM UTC
   
 
Category:  Library Severity:  4 - Important
Priority:  7 - High Item Group:  libc code
Status:  Fixed Assigned to:  joerg_wunsch
Percent Complete:  0% Open/Closed:  Closed
Release:  None Fixed Release:  None

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>
Group administrator
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.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-01-08 joerg_wunsch StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2007-01-08 joerg_wunsch StatusConfirmed In Progress
    2007-01-08 joerg_wunsch Item GroupNone libc code
    2007-01-08 joerg_wunsch Severity3 - Normal 4 - Important
        Priority5 - Normal 7 - High
        StatusNone Confirmed
        Assigned toNone joerg_wunsch

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code