Module:RNG
basically a few functions that deal with randomness and random text
how 2 random
this module contains five functions, which each generate random strings with different sets of characters:
number- generates a random numberalphabet- generates a random string using only lettersalphanumeric- generates a random string using uppercase and lowercase letters, and numberssymbols- generates a random string using only symbols and punctuationstring- generates a random string using any characters
this module can be called like so:
{{#invoke: RNG | (function name) | (length) | (case (alphabet function only))}}
the alphabet function has an additional parameter, used for determining the case of the letters.
- when
caseis set toupper, letters will always be uppercase. - when
caseis set tolower, letters will always be lowercase. - when
caseis set toboth(or anything else), case will be random.
randomness from this module is cached, meaning the user will have to refresh the page while ignoring cache (ctrl + f5) in order to reroll for new values.
examples
{{#invoke: RNG | number | 6}} will result in a random six digit number:
695090
{{#invoke: RNG | alphabet | 8 | upper}} will result in a random 8 letter string in all caps:
btCfgxdk
{{#invoke: RNG | alphanumeric | 15}} will result in a random 15 character string, with numbers and letters:
1C5D4792UV2K74A
{{#invoke: RNG | symbols | 5}} will result in a random 5 character string with only symbols and punctuation:
- %&+=
{{#invoke: RNG | string | 20}} will result in a Password:
42[8X0n`97rTt184:Y2m
p = {}
math.randomseed(os.time() + os.clock() * 1000000000)
local characters = {
{1,2,3,4,5,6,7,8,9,0},
{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'},
{'`','~','!','@','#','$','%','^','&','*','(',')','-','_','=','+','[','{',']','}',';',':',"'",'"',',','<','.','>','/','?','\\','|'}
}
p.number = function(frame)
math.randomseed(os.time() + os.clock() * 1000000000)
local s = ''
local length = tonumber(frame.args[1]) or 10
for i=1, length do
s = s .. characters[1][math.random(1,#characters[1])]
end
return s
end
p.alphabet = function(frame)
math.randomseed(os.time() + os.clock() * 1000000000)
local s = ''
local length = tonumber(frame.args[1]) or 10
local case = frame.args[2] or 'both'
for i=1, length do
if case == 'upper' then
c = characters[2][math.random(1,#characters[2])]:upper()
elseif case == 'both' then
if math.random(1,2) == 1 then c = characters[2][math.random(1,#characters[2])]:upper() else c = characters[2][math.random(1,#characters[2])] end
elseif case == 'lower' then
c = characters[2][math.random(1,#characters[2])]
else
if math.random(1,2) == 1 then c = characters[2][math.random(1,#characters[2])]:upper() else c = characters[2][math.random(1,#characters[2])] end
end
s = s .. c
end
return s
end
p.alphanumeric = function(frame)
math.randomseed(os.time() + os.clock() * 1000000000)
local s = ''
local length = tonumber(frame.args[1]) or 10
for i=1, length do
if math.random(1,2) == 1 then
c = p.number({args={1}})
else
c = p.alphabet({args={1}})
end
s = s .. c
end
return s
end
p.symbols = function(frame)
math.randomseed(os.time() + os.clock() * 1000000000)
local s = ''
local length = tonumber(frame.args[1]) or 10
for i=1, length do
s = s .. characters[3][math.random(1,#characters[3])]
end
return s
end
p.string = function(frame)
math.randomseed(os.time() + os.clock() * 1000000000)
local s = ''
local length = tonumber(frame.args[1]) or 10
for i=1, length do
local j = math.random(1,3)
if j == 1 then
c = p.number({args={1}})
elseif j == 2 then
c = p.alphabet({args={1}})
else
c = p.symbols({args={1}})
end
s = s .. c
end
return s
end
p.seed = function() -- don't use this one i'm testing something
math.randomseed(os.time() + os.clock() * 1000000000)
return os.time() + os.clock() * 1000000001
end
return p