method
rand
v1_9_3_125 -
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 (0)
- 1_9_3_392 (0)
- 2_1_10 (38)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
rand(*args)
public
When the argument is an Integer or a Bignum, it returns a random integer greater than or equal to zero and less than the argument. Unlike Random.rand, when the argument is a negative integer or zero, it raises an ArgumentError.
When the argument is a Float, it returns a random floating point number between 0.0 and max, including 0.0 and excluding max.
When the argument limit is a Range, it returns a random number where range.member?(number) == true.
prng.rand(5..9) #=> one of [5, 6, 7, 8, 9] prng.rand(5...9) #=> one of [5, 6, 7, 8] prng.rand(5.0..9.0) #=> between 5.0 and 9.0, including 9.0 prng.rand(5.0...9.0) #=> between 5.0 and 9.0, excluding 9.0
begin/end of the range have to have subtract and add methods.
Otherwise, it raises an ArgumentError.