PDA

View Full Version : Generating True Random Numbers



S Ferguson
May 29th, 2013, 18:35
I'm a little stumped here. math.random(i,j) delivers a pseudo-random number, but one that propagates from session to session, randomseed(i) can't be seeded off the system clock (lack of os.time library function), and I reallllly hate things being repeated each run of the session. Anyone happen to have a workaround to this issue? I'd be very grateful and you'd earn a merit badge :D.

sakmerlin37
June 26th, 2013, 20:28
@S Ferguson

I searched for this and the best I got was someone else's attempt to fix the pseudo-random problem using:



do
local oldrandom = math.random
local randomtable
math.random = function ()
if randomtable == nil then
randomtable = {}
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
endend


See the following link for original conversation: https://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-general/302580-there-lua-random-number-function.html

Hope that helps :)

S Ferguson
June 26th, 2013, 20:31
@S Ferguson

I searched for this and the best I got was someone else's attempt to fix the pseudo-random problem using:



snipped


See the following link for original conversation: https://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-general/302580-there-lua-random-number-function.html

Hope that helps :)

It does. Thank you. It's much appreciated,
SF