[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] [bug #18662] rand() keeps returning the same value if see
From: |
Roland Bluethgen |
Subject: |
[avr-libc-dev] [bug #18662] rand() keeps returning the same value if seeded with 0 |
Date: |
Sun, 31 Dec 2006 13:57:11 +0000 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9 |
URL:
<http://savannah.nongnu.org/bugs/?18662>
Summary: rand() keeps returning the same value if seeded
with 0
Project: AVR C Runtime Library
Submitted by: calocybe
Submitted on: Sunday 12/31/2006 at 14:57
Category: Library
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: None
Status: None
Privacy: Public
Percent Complete: 0%
Assigned to: None
Originator Email: calocybe
Open/Closed: Open
Discussion Lock: Any
_______________________________________________________
Details:
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.
_______________________________________________________
Reply to this item at:
<http://savannah.nongnu.org/bugs/?18662>
_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-dev] [bug #18662] rand() keeps returning the same value if seeded with 0,
Roland Bluethgen <=