Description
|
Generates a random value in the range between 0 and 1. The value is generated from an individual generator attach to the calling script (i.e. scripts do not share a common generator as is the case with Lua's math.random function). sim.getRandom has however also been wrapped inside of two new Lua functions, in order to mimic Lua's math.random and math.randomseed:
function math.random2(lower,upper)
local r=sim.getRandom()
if lower then
local b=1
local d
if upper then
b=lower
d=upper-b
else
d=lower-b
end
local e=d/(d+1)
r=b+math.floor(r*d/e)
end
return r
end
function math.randomseed2(seed)
sim.getRandom(seed)
end
|