Module:Random choice
Returns a random pipe-separated segment of the argument (for {{Random choice}}).
Is made to be above all fast, the probability of an argument being chosen is proportional to its length.
local p = {}
local getArgs = require("Module:Arguments").getArgs
function p.main(frame)
args = getArgs(frame)
s = args[1]
math.randomseed(os.time())
i = math.floor(math.random()*#s)
j = i+1
while (string.sub(s, i, i) ~= "|" and i > 0) do
i = i - 1
end
while (string.sub(s, j, j) ~= "|" and j < #s) do
j = j + 1
end
return string.sub(s, i+1, j-1)
end
return p