Code: Select all
local x = love.math.random(1, 4)
local y = love.math.random(1, 4) -- y ~= x
Code: Select all
local x = love.math.random(1, 4)
local y = love.math.random(1, 4) -- y ~= x
Code: Select all
local x = love.math.random(1, 4)
local y = love.math.random(1, 3)
if x == y then y = y + 1 end
Code: Select all
local x, y
x = love.math.random(1, 4)
repeat
y = love.math.random(1, 4)
until x ~= y
Code: Select all
local list = {1, 2, 3, 4}
local N = #list
local numbers_to_extract = 2
for i = 1, numbers_to_extract do
local rand = math.random(i, N)
list[i], list[rand] = list[rand], list[i]
end
This isn't uniform. You will only get a 4 in the second number if the first one is a 3, so the pairs (1, 4) and (2, 4) don't appear at all. I think you meant <= instead of ==.Nelvin wrote: ↑Tue May 07, 2019 8:09 pm Most simple/pragmatic solution
Code: Select all
local x = love.math.random(1, 4) local y = love.math.random(1, 3) if x == y then y = y + 1 end
Good catch, haven't really thought about it - but it's also a question of the actual range of values used. If it's about a random position on a fullHD display, it doesn't matter, but for lower ranges, my suggestion was/is pure crap.pgimeno wrote: ↑Tue May 07, 2019 11:02 pmThis isn't uniform. You will only get a 4 in the second number if the first one is a 3, so the pairs (1, 4) and (2, 4) don't appear at all.Nelvin wrote: ↑Tue May 07, 2019 8:09 pm Most simple/pragmatic solution
Code: Select all
local x = love.math.random(1, 4) local y = love.math.random(1, 3) if x == y then y = y + 1 end
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 7 guests