method
rand
v1_9_2_180 -
Show latest stable
-
0 notes -
Class: Random
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180 (0)
- 1_9_3_125 (-38)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
rand(p1 = v1)
public
Converts max to an integer using max1 = max.to_i.abs. If max is nil the result is zero, returns a pseudorandom floating point number greater than or equal to 0.0 and less than 1.0. Otherwise, returns a pseudorandom integer greater than or equal to zero and less than max1. Kernel::srand may be used to ensure repeatable sequences of random numbers between different runs of the program. Ruby currently uses a modified Mersenne Twister with a period of 2**19937-1.
srand 1234 #=> 0 [ rand, rand ] #=> [0.191519450163469, 0.49766366626136] [ rand(10), rand(1000) ] #=> [6, 817] srand 1234 #=> 1234 [ rand, rand ] #=> [0.191519450163469, 0.49766366626136]