Code: Select all
function love.load()
rng = love.math.newRandomGenerator()
rng:setSeed(os.time())
randomNumber = rng:random(1,100)
assert(nil, randomNumber)
end
Code: Select all
function love.load()
rng = love.math.newRandomGenerator()
rng:setSeed(os.time())
randomNumber = rng:random(1,100)
assert(nil, randomNumber)
end
Code: Select all
function love.load()
rng = love.math.newRandomGenerator()
rng:setSeed(os.time())
rng:random()
randomNumber = rng:random(1,100)
assert(nil, randomNumber)
end
Code: Select all
function love.load()
rng = love.math.newRandomGenerator()
rng:setSeed(tonumber(tostring(os.time()):reverse()))
randomNumber = rng:random(1,100)
assert(nil, randomNumber)
end
Code: Select all
8, 8, 7, 6, 5, 4, 3
Code: Select all
1, 2, 3, 4, 5, 6, 1
Code: Select all
function Random(min, max, isFractional)
local gen = love.math.newRandomGenerator()
gen:setSeed(os.time())
local isFractional = isFractional or false
local randomNumber
if isFractional == true then
randomNumber = gen:random(min * 100, max * 100) / 100 -- math random doesn't play nice with decimals..
else
randomNumber = gen:random(min, max)
end
assert(nil, randomNumber) -- some debug junk
return randomNumber
end
Code: Select all
Random(- 5, 5, true)
Code: Select all
function Random(min, max, isFractional)
local gen = love.math.newRandomGenerator()
gen:setSeed(os.time())
gen:random()
local isFractional = isFractional or false
local randomNumber
if isFractional == true then
randomNumber = gen:random(min * 100, max * 100) / 100 -- math random doesn't play nice with decimals..
else
randomNumber = gen:random(min, max)
end
assert(nil, randomNumber) -- some debug junk
return randomNumber
end
Code: Select all
local gen = love.math.newRandomGenerator()
gen:setSeed(os.time())
gen:random()
function Random(min, max, isFractional)
local randomNumber
if isFractional then
randomNumber = gen:random(min * 100, max * 100) / 100 -- math random doesn't play nice with decimals..
else
randomNumber = gen:random(min, max)
end
assert(nil, randomNumber) -- some debug junk
return randomNumber
end
Oh, that's perfect, thanks for throwing that my way, I didn't know that existed.bartbes wrote:love.math.random
I'll keep that in mind, thanks! I tested out the example you posted in LOVE though and it still seems to generate a number "like clockwork". Maybe it's because of the way I'm testing it, but I don't think that should matter.Robin wrote:A function that returns or uses a pseudo-random number should not mess with the seed.
Users browsing this forum: Amazon [Bot], Google [Bot] and 13 guests