wowpedia
Main Menu


Returns a random number within the specified interval.

rand = fastrandom([ [low, ] high])

Arguments

low
number - lower integer limit on the returned random value.
high
number - upper integer limit on the returned random value.

Returns

rand
number - Generated random value. If no arguments were specified, the value is a uniformly-distributed decimal between 0 (inclusive) and 1 (exclusive). Otherwise, returns a uniformly-distributed integer between low (1 if not specified) and high, both bounds inclusive.

Details

local state = 0 -- initialized by seeding
function random(high)
 state = (state * 214013 + 2531011) % 2^32;
 local rand = math.floor(state / 2^16) % 2^15;
 return 1 + math.floor(rand / 0x7fff * high)
end

See also

Patch changes

Mists of Pandaria Patch 5.4.2 (2013-12-10): Name changed to fastrandom; random and math.random now use a different RNG algorithm.