Module:Random: Difference between revisions

From Modded Wiki
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 2 revisions imported
 
(One intermediate revision by one other user not shown)
Line 20: Line 20:
seeded = true
seeded = true
end
function p.main( frame )
local m = tonumber( frame.args[1] )
local n = tonumber( frame.args[2] )
return tostring( p.random( n and m or m and 1 or 0, n or m or 1 ) )
end
end


return p
return p

Latest revision as of 08:10, 4 July 2024

Documentation for this module may be created at Module:Random/doc

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

function p.main( frame )
	local m = tonumber( frame.args[1] )
	local n = tonumber( frame.args[2] )
	
	return tostring( p.random( n and m or m and 1 or 0, n or m or 1 ) )
end

return p