math.random

Generate a random number

Prototype

v = math.random (n, u)

Description

With no arguments, returns a random number in the range [0, 1). That is, zero up to but excluding 1.

With 1 argument, returns an integer in the range [1, n]. That is from 1 up to and including n.

With 2 arguments, returns an integer in the range [n, u]. That is from n up to and including u.

Use math.randomseed to seed the generator.

math.random () --> 0.30195013275552 (for example)
math.random (5)  --> (a number from 1 to 5)
math.random (4, 8)  --> (a number from 4 to 8)
Also see the world.MtRand function for random numbers generated by the Mersenne Twister algorithm.

Lua functions

Topics