Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.7.0.pre2
-
Fix Version/s: JRuby 1.7.0.RC2
-
Component/s: Ruby 1.9.3, RubySpec
-
Labels:None
-
Environment:Mac OS X 10.7.4 Java 1.7.0_05
-
Number of attachments :
Description
From ruby 1.9.3 documentation:
rand(max=0) -> number
If max is Range, returns a pseudorandom number where range.member(number) == true
But I am getting a TypeError:
jruby-1.7.0.preview2 :001 > rand 1..7 TypeError: can't convert Range into Integer from org/jruby/RubyKernel.java:1580:in `rand' from (irb):1:in `evaluate' from org/jruby/RubyKernel.java:1070:in `eval' from org/jruby/RubyKernel.java:1395:in `loop' from org/jruby/RubyKernel.java:1178:in `catch' from org/jruby/RubyKernel.java:1178:in `catch' from /Users/tim/.rvm/rubies/jruby-1.7.0.preview2/bin/irb:17:in `(root)'
Needs a bit of porting, but the logic is found in MRI in the C "rand_range" function, called before it attempts to coerce to an Integer. We just proceed straight to the coercion.