Random.rand is broken with floating point values vs 1.9.3 #1583

Closed
twooster opened this Issue Mar 26, 2014 · 2 comments

Projects

None yet

3 participants

@twooster

Observed Behavior

In JRuby 1.7.9 (and reviewed code on master branch, still exhibited) Random.rand(some_float) performs a .to_i on some_float before calculation, thus returning an integer from 0 up to some_float.to_i.

Expected Behavior

Since MRI 1.9.3, Random.rand(some_float) should return a floating point value between 0 and some_float. JRuby since 1.7.0 should have this behavior.

Other

Important: Even in Ruby 2.0, Kernel.rand maintains the old (MRI 1.9.2) Random.rand behavior presently exhibited in JRuby's implementation.

MRI 1.9.2:

>> Kernel.rand(1.0)
=> 0 # always
>> Random.rand(1.0)
=> 0 # always

MRI 1.9.3:

>> Kernel.rand(1.0)
=> 0 # always
>> Random.rand(1.0)
=> 0.7766500784403212 # random, of course

JRuby 1.7.9 (expected the same as MRI 1.9.3 above):

>> Kernel.rand(1.0)
=> 0 # always
>> Random.rand(1.0)
=> 0 # always
@enebo enebo added this to the JRuby 1.7.12 milestone Apr 2, 2014
@enebo
JRuby Team member

This was corrected in commit 474ecbd on jruby-1_7 branch.

@enebo
JRuby Team member

cherry-picked that over to master. We have done multiple merges since then so I am confused why it was missing.

@enebo enebo closed this Apr 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment