You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the math.randomseed(n) function is called with float values < 1 then subsequent calls to math.random() yields the same amount.
The work-around is to seed the RNG using integers and not float values derived from math.random(). This ticket is a reminder of this fact, and also to document the steps to test, for anybody encountering this in the future.
Test Case
localseed_bag= {}
functionlove.draw ()
love.graphics.print("click to generate random numbers, watch the web console.")
endfunctionlove.mousepressed(x, y, button, istouch)
if#seed_bag==0thenprint("filling bag with seeds.")
fori=0, 10dotable.insert(seed_bag, math.random())
endendnext_seed=table.remove(seed_bag)
print("set random seed of " ..next_seed)
math.randomseed(next_seed)
random_amount=math.random(100, 500)
print("random amount between 100 and 500 for this seed equals " ..random_amount)
end
The above code outputs the following when run in Löve on the Desktop:
filling bag with seeds.
set random seed of 0.11446190140255
random amount between 100 and 500 for this seed equals 319
set random seed of 0.56859228170254
random amount between 100 and 500 for this seed equals 389
set random seed of 0.42668680786097
random amount between 100 and 500 for this seed equals 479
set random seed of 0.73573903003308
random amount between 100 and 500 for this seed equals 378
set random seed of 0.33933341140343
random amount between 100 and 500 for this seed equals 150
etc cetera
The same code running via Löve .js:
filling bag with seeds.
set random seed of 0.421925941213
random amount between 100 and 500 for this seed equals 482
set random seed of 0.6700635201624
random amount between 100 and 500 for this seed equals 482
set random seed of 0.31313096560218
random amount between 100 and 500 for this seed equals 482
set random seed of 0.60369106969037
random amount between 100 and 500 for this seed equals 482
ad infinitum ...
This behaviour does not happen when the seed value is an integer value > 0.
The text was updated successfully, but these errors were encountered:
Problem Statement
When the
math.randomseed(n)
function is called with float values < 1 then subsequent calls tomath.random()
yields the same amount.The work-around is to seed the RNG using integers and not float values derived from
math.random()
. This ticket is a reminder of this fact, and also to document the steps to test, for anybody encountering this in the future.Test Case
The above code outputs the following when run in Löve on the Desktop:
The same code running via Löve .js:
This behaviour does not happen when the seed value is an integer value > 0.
The text was updated successfully, but these errors were encountered: