Skip to main content

randomseed

Function randomseed 

Source
pub fn randomseed(x: option<number>, y: option<number>) -> (number, number)
Expand description

Initialises the pseudo-random number generator.

§Parameters

  • x: an integer used as seed.
  • y: an integer used as a second seed component.

§Return value

The two integer components of the seed that was set, so they can be reused later to repeat the sequence.

§Description

Equal seeds produce equal sequences of numbers. When called with no arguments, Lua generates a seed with a weak attempt for randomness. (Since Lua the generator is seeded automatically at startup, so calling this function is only needed to reproduce a sequence.)

§Examples

math.randomseed(42)
print(math.random(100))   --> always the same value for seed 42

§See also

random