util.math.randomseed
Shared
Sets the seed for the pseudo-random number generator
Syntax
util.math.randomseed(
seed,
seed_extra = nil
)Parameters
| Type | Name | Description |
|---|---|---|
int | seed | Primary seed value |
int | seed_extra | Optional secondary seed value for a wider seed range |
Returns
This function does not return any values.
Examples
util.math.randomseed(42)
core.engine.print("info", util.math.random(100)) -- always the same valueutil.math.randomseed(os.time())
core.engine.print("info", util.math.random(100)) -- varies per runutil.math.randomseed(1234)
local a = util.math.random(1000)
util.math.randomseed(1234)
local b = util.math.random(1000)
core.engine.print("info", a == b) -- trueutil.math.randomseed(7)
local deck = {}
for i = 1, 10 do
deck[i] = i
end
for i = #deck, 2, -1 do
local j = util.math.random(i)
deck[i], deck[j] = deck[j], deck[i]
end
core.engine.iprint(deck)util.math.randomseed(os.time(), os.clock()*1e9)
core.engine.print("info", util.math.random()) -- 0.74392 (varies)