Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

Projects
None yet
3 participants
@twooster
Copy link

twooster commented Mar 26, 2014

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

@BanzaiMan BanzaiMan added core labels Mar 29, 2014

@enebo enebo added this to the JRuby 1.7.12 milestone Apr 2, 2014

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Apr 2, 2014

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

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Apr 2, 2014

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
You can’t perform that action at this time.