Module:Random: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local p = {} local seeded local randomseed = math.randomseed local random = math.random function p.random( m, n ) if not seeded then p.seed() end return random( n and...") |
m (1 revision imported: Imported from minecraft.wiki) |
(No difference)
|
Latest revision as of 07:41, 24 October 2023
This is the documentation page. It will be transcluded into the main module page. See Template:Documentation for more information
This module generates a pseudo-random number. It is used the same as math.random
, however it first sets up a seed so that the number is actually random.
de:Modul:Zufall
ru:Модуль:Случайные числа
local p = {}
local seeded
local randomseed = math.randomseed
local random = math.random
function p.random( m, n )
if not seeded then
p.seed()
end
return random( n and m or m and 1 or 0, n or m or 1 )
end
function p.seed( seed )
randomseed( seed or ( os.time() + os.clock() * 1000000000 ) )
-- First few values of seed is not guaranteed to be random on some platforms
random()
random()
seeded = true
end
return p