Expose core random number functions to lua
Expose nh.rn2() and nh.random() to lua. Add a math.random() compatibility shim to nhlib.lua
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
|
||||
math.randomseed( os.time() )
|
||||
-- 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
|
||||
|
||||
Reference in New Issue
Block a user