Method: Kernel#rand

Defined in:
lib/source/ruby.rb

#rand(num = 0) ⇒ Object

call-seq:

rand(num = 0) -> numeric

Converts num to the integer max equivalent to num.to_i.abs. If max is zero, returns a pseudo-random floating point number greater than or equal to 0 and less than 1. Otherwise, returns a pseudo-random integer greater than or equal to zero and less than max.

rand        #=> 0.7137224264409899
rand(10)    #=> 2
rand(100)   #=> 79


1426
1427
1428
1429
# File 'lib/source/ruby.rb', line 1426

def rand(num = 0)
  `var max=Math.abs(parseInt(num))`
  `max==0?Math.random():parseInt(Math.random()*max)`
end