TypeFunction Librarymath.* Return valueNumber Revision2019.3459 Keywordsrandom, random number See alsomath.randomseed()

Returns a pseudo-random number from a sequence with uniform distribution.

This function is an interface to the simple pseudo-random generator function `rand`

provided by ANSI C. No guarantees can be given for its statistical properties.

There are three usage options for this function:

- When called without arguments, returns a uniform
pseudo-random real number in the range`[0,1]`

. - When called with an integer number
`m`

,`math.random`

returns a uniformpseudo-random integer in the range`[1,m]`

. - When called with two integer numbers
`m`

and`n`

,`math.random`

returns a uniformpseudo-random integer in the range`[m,n]`

.

Note

The random number generator needs to be started with a seed using math.randomseed() before this function is called or else it will generate the same sequence every time. While this is useful for testing, it is more usual to get a different random sequence each run by using a different seed

math.random() math.random( m ) math.random( m, n )

*Number.* A number.

*Number.* A number.

print(math.random()) --> a number between 0 and 1 print(math.random()) --> another number between 0 and 1 print(math.random(10)) --> an integer between 1 and 10 (inclusive) print(math.random(70, 80)) --> an integer between 70 and 80 (inclusive)