Skip to main content

random

Function random 

Source
pub fn random(m: option<number>, n: option<number>) -> number
Expand description

Returns a pseudo-random number.

§Parameters

  • m: an integer, the lower bound (or the upper bound of the range [1, m], when n is absent).
  • n: an integer, the upper bound.

§Return value

With no arguments, a pseudo-random float with uniform distribution in the range [0, 1). With one or two integer arguments, a pseudo-random integer with uniform distribution in the range [1, m] or [m, n], respectively.

§Examples

print(math.random())        --> 0.2896938390679077  (some float in [0, 1))
print(math.random(6))       --> 4                 (a die roll: 1..6)
print(math.random(10, 20))  --> 17                (an integer in 10..20)

§See also

randomseed