Project

General

Profile

Actions

Backport #7935

closed

Array#sample with random generator

Added by marcandre (Marc-Andre Lafortune) about 11 years ago. Updated about 11 years ago.


Description

The Random generator method's rand is called with the wrong limit.

Kernel::rand(n) returns integer between 0 and n-1, but generator is called with (n-1).

For example:

require 'delegate'
[1, 2].sample(1, random: Random.new) # => [1], or [2]
[1, 2].sample(1, random: SimpleDelegator.new(Random.new)) # => [1], never [2]

test_random_ulong_limited

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0