Bug #4590
closeddocumentation is wrong for srand
Description
=begin
'ri srand' (in random.c) suggests that passing 0 generates a seed number:
If number is omitted or zero, seeds the generator using a combination of (...)}
Currently, this isn't true (0 is a valid seed):
srand(10); srand; srand
=> 290577086691033874500011807841900203857
srand(10); srand(0); srand(0)
=> 0
It should be:
If number is omitted, seeds the generator using a combination of (...)
I would normally create a patch for this, but wouldn't it be less surprising if srand accepted nil for generating the random seed?
Instead of code like:
prev_seed = (seed == nil ? srand : srand(seed))
we would have:
prev_seed = srand(seed)
Would this be a good idea?
Currently this fails, because an integer is expected:
srand(nil)
TypeError: can't convert nil into Integer
=end
Updated by naruse (Yui NARUSE) about 13 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
This issue was solved with changeset r31316.
Cezary, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- random.c (rb_f_srand): fix rdoc: srand(0)'s 0 is a seed.
[ruby-core:35833] fixes #4590
=end