Project

General

Profile

Actions

Bug #1855

closed

Random#int with Single-Element Ranges

Added by runpaint (Run Paint Run Run) almost 15 years ago. Updated about 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-08-01 trunk 24343) [i686-linux]
Backport:
[ruby-core:24655]

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

Actions #1

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

Actions #2

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

Also available in: Atom PDF

Like0
Like0Like0