[Home] [Downloads] [Search] [Help/forum]



Generate a random number


v = math.random (n, u)


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.

See Also ...

Lua functions

math.abs - Absolute value
math.acos - Arc cosine
math.asin - Arc sine
math.atan - Arc tangent
math.atan2 - Arc tangent of v1/v2
math.ceil - Next higher integer value
math.cos - Cosine
math.cosh - Hyperbolic cosine
math.deg - Convert from radians to degrees
math.exp - Raises e to a power
math.floor - Next smaller integer value
math.fmod - The modulus (remainder) of doing: v1 / v2
math.frexp - Break number into mantissa and exponent
math.huge - A huge value
math.ldexp - Compute m* 2^n
math.log - Natural log
math.log10 - Log to the base 10
math.max - The highest of one or more numbers
math.min - The lowest of one or more numbers
math.modf - Returns the integral and fractional part of its argument
math.pi - The value of pi
math.pow - Raise a number to a power
math.rad - Convert degrees to radians
math.randomseed - Seeds the random number generator
math.sin - Sine
math.sinh - Hyperbolic sine
math.sqrt - Square root
math.tan - Tangent
math.tanh - Hyperbolic tangent


Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting callbacks - plugins

(Help topic: lua=math.random)

Documentation contents page

Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]