Actions
Bug #1855
closedRandom#int with Single-Element Ranges
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-08-01 trunk 24343) [i686-linux]
Backport:
Description
=begin
Random#int accepts a Range argument from which it chooses values. If the range contains only one element, #int returns it on every call. This is unlikely to be what a user intended. I suggest that if the range's #begin value is equal to its #end value, an ArgumentError is raised.
prng = Random.new
=> #Random:0x9b446b0
4.times.map { prng.int(2...3) }
=> [2, 2, 2, 2]
=end
Updated by runpaint (Run Paint Run Run) almost 15 years ago
=begin
A range of Floats also behaves like a single-element Range, which is surely wrong.
prng = Random.new
=> #Random:0x9bb2160
4.times.map { prng.int(1.0..10.0) }
=> [1.0, 1.0, 1.0, 1.0]
=end
Updated by nobu (Nobuyoshi Nakada) over 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r24670.
=end
Actions
Like0
Like0Like0