2023年政策修订增补工作正在进行中,欢迎参与!
Module:Sandbox/红石小蝈/Dice
< Module:Sandbox | 红石小蝈
local ret = {}
prime = 998244353
local function fastpow(a, b, mod)
local n = 1
local r = a
local p = b
while p > 0 do
if p % 2 == 1 then
n = n * r % mod
end
r = r * r % mod
p = (p-(p%2)) / 2
end
return n
end
local function seed(frame)
local t = os.time()
t = fastpow(3, t, prime)
return t
end
rand = {}
rand.seed = seed()
rand.dice = function(num)
rand.seed = rand.seed * 114514 % prime
if num <= prime then
return rand.seed%num
else
return fastpow(num % prime, rand.seed, num)
end
end
rand.run = function(str)
local stack = {0, 0}
stack.top = 0
for i = 1, mw.ustring.len(str) do
local chr = mw.ustring.sub(str, i, i)
local ord = mw.ustring.byte(chr)
if ord >= 48 and ord < 58 then
stack.top = stack.top * 10 + (ord - 48)
elseif chr == 'd' or chr == 'D' then
end
end
end
ret.seed = seed
return ret