Expose nh.rn2() and nh.random() to lua. Add a math.random() compatibility shim to nhlib.lua
24 lines
519 B
Lua
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);
|