Project

General

Profile

This project is closed and read-only.

Actions

Backport #7935

closed

Array#sample with random generator

Backport #7935: Array#sample with random generator

Added by marcandre (Marc-Andre Lafortune) over 13 years ago. Updated over 13 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: PDF Atom