Files
nethack/dat/nhlib.lua
Pasi Kallinen eec9c2e209 Expose core random number functions to lua
Expose nh.rn2() and nh.random() to lua.
Add a math.random() compatibility shim to nhlib.lua
2020-03-25 12:24:32 +02:00

24 lines
519 B
Lua

-- compatibility shim
math.random = function(...)
local arg = {...};
if (#arg == 1) then
return 1 + nh.rn2(arg[1]);
elseif (#arg == 2) then
return nh.random(arg[1], arg[2] + 1 - arg[1]);
else
-- we don't support reals
error("NetHack math.random requires at least one parameter");
end
end
function shuffle(list)
for i = #list, 2, -1 do
local j = math.random(i)
list[i], list[j] = list[j], list[i]
end
end
align = { "law", "neutral", "chaos" };
shuffle(align);