Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Sakretsu
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} function p.main(frame) local max = tonumber(frame.args[1]) if not max then return end local n = string.match(mw.site.stats.edits + mw.site.stats.pages + os.time(), '%d%d%d$') n = tonumber(n) while n > max do n = n - max end return n end local function getBigRandom(l, u) -- Gets a random integer between l and u, and is not limited to RAND_MAX. math.randomseed(mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000)) local r = 0 local n = 2^math.random(30) -- Any power of 2. local limit = math.ceil(53 / (math.log(n) / math.log(2))) for i = 1, limit do r = r + math.random(0, n - 1) / (n^i) end return math.floor(r * (u - l + 1)) + l end function p.number(frame) -- Gets a random number. first = tonumber(frame.args[1]) second = tonumber(frame.args[2]) -- This needs to use if statements as math.random won't accept explicit nil values as arguments. if first then if second then if first > second then -- Second number cannot be less than the first, or it causes an error. first, second = second, first end return getBigRandom(first, second) else return getBigRandom(1, first) end else return math.random() end end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Sakretsu/doc
(
edit
)