Backport #7935
Array#sample with random generator
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
Associated revisions
random.c: increase limit for generic rand
- random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935]
random.c: increase limit for generic rand
- random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935]
random.c: increase limit for generic rand
- random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935]
random.c: increase limit for generic rand
- random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935]
random.c: increase limit for generic rand
- random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935]
random.c: increase limit for generic rand
- random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935]
test_array.rb: fix test for r39466
- test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
test_array.rb: fix test for r39466
- test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
test_array.rb: fix test for r39466
- test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
test_array.rb: fix test for r39466
- test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
test_array.rb: fix test for r39466
- test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
test_array.rb: fix test for r39466
- test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
test_array.rb: fix test for r39466
- test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
merge revision(s) 39466,39470: [Backport #7935]
* random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935] * test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@39675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 39466,39470: [Backport #7935]
* random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935] * test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
History
Updated by nobu (Nobuyoshi Nakada) almost 6 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r39466.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
random.c: increase limit for generic rand
- random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935]
Updated by nobu (Nobuyoshi Nakada) almost 6 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby trunk to Backport200
- Category deleted (
core) - Status changed from Closed to Assigned
- Assignee set to mame (Yusuke Endoh)
- Target version deleted (
2.6)
Updated by nagachika (Tomoyuki Chikanaga) almost 6 years ago
- Assignee changed from mame (Yusuke Endoh) to nagachika (Tomoyuki Chikanaga)
Updated by nagachika (Tomoyuki Chikanaga) almost 6 years ago
- Status changed from Assigned to Closed
This issue was solved with changeset r39675.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 39466,39470: [Backport #7935]
* random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935] * test/ruby/test_array.rb (test_sample_random): remove adjustment for the bug fixed by r39466. [ruby-core:52779] [Bug #7935]
random.c: increase limit for generic rand
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e