random number function (simple)

Here’s a simple random number function for ya’ll, which actually returns random numbers!

The “do” block replaces the “built in” random feature in Lua. So it must be in your code above the randomNumber() function below.

[lua]do
local oldrandom = math.random
local randomtable
math.random = function ()
if randomtable == nil then
randomtable = {}
– 97 is a nice, relatively large prime number
for i = 1, 97 do
randomtable[i] = oldrandom()
end
end
local x = oldrandom()
local i = 1 + math.floor(97*x)
x, randomtable[i] = randomtable[i], x
return x
end
end

function randomNumber(minNum, maxNum)
local retval = minNum + math.floor(math.random() * (maxNum - minNum + 1))
return retval
end[/lua] [import]uid: 616 topic_id: 16720 reply_id: 316720[/import]

Thanks mrgoose, I’ll definitely give it a try! [import]uid: 40033 topic_id: 16720 reply_id: 62636[/import]