Module:Sandbox/Hellknowz/Misc

Revision as of 10:37, 28 November 2013 by imported>Mr. Stradivarius (r2 needs to use math.ceil, not math.floor - but nice algorithm! It's a lot easier to understand as code.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Sandbox/Hellknowz/Misc/doc

local p = {}

function p.rand(max)
	
	math.randomseed(mw.site.stats.edits)
	
	if (max <= 2147483648) then
		return math.random(max)
	else
		local ratio = max / 2147483648
		local r1 = math.floor(math.random(2147483648-1) * ratio)
		local r2 = math.random(math.ceil(ratio))
		return r1 + r2
	end
	
end

function p.random(frame)
	return p.rand(0 + frame.args[1])
end
 
return p