Project

General

Profile

Actions

Bug #4590

closed

documentation is wrong for srand

Added by Cezary (Cezary Baginski) about 13 years ago. Updated about 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
r31311
Backport:
[ruby-core:35833]

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

Actions

Also available in: Atom PDF

Like0
Like0