Page 2 of 2

Re: Random Generation map error on Mobile

Posted: Wed Aug 17, 2022 12:22 pm
by darkfrei
Gunroar:Cannon() wrote: Wed Aug 17, 2022 9:42 am
darkfrei wrote: Tue Aug 16, 2022 5:00 pm
GVovkiv wrote: Tue Aug 16, 2022 4:54 pm Also, it's, probably, better to use love.math.random, and not lua's math.random
No, math.random is better, but by the testing use the same seed, you don't need to get the error sometimes.
Woah, why?
math.random is in LuaJIT and is much more random than love.math.random. Maybe also faster :)

Re: Random Generation map error on Mobile

Posted: Wed Aug 17, 2022 3:05 pm
by zorg
darkfrei wrote: Wed Aug 17, 2022 12:22 pm
Gunroar:Cannon() wrote: Wed Aug 17, 2022 9:42 am
darkfrei wrote: Tue Aug 16, 2022 5:00 pm

No, math.random is better, but by the testing use the same seed, you don't need to get the error sometimes.
Woah, why?
math.random is in LuaJIT and is much more random than love.math.random. Maybe also faster :)
Not really.

First off, math.random exists in all kinds of lua, not just luaJIT; second, the math.random of luaJIT specifically uses one kind of pseudo-random generator algorithm, that should be consistent regardless of platform (similarly with löve's own PRNG implementation). Löve's own uses a different algorithm.

Neither is "more random" than the other. Speed differences really shouldn't matter. The only big noticeable difference is that luaJIT's math.random is not initially seeded, so you'll probably always get the same run of values unless you call the seeding function yourself.

The only one that would be bad is the regular lua one that uses some OS PRNG, which can be bad... but no official löve release uses vanilla lua anyway so that's irrelevant.

Re: Random Generation map error on Mobile

Posted: Wed Aug 17, 2022 3:33 pm
by pgimeno
darkfrei wrote: Wed Aug 17, 2022 12:22 pm math.random is in LuaJIT and is much more random than love.math.random[citation required]. Maybe also faster :)
Löve's random number generator uses FFI to allow it to be compiled. It's not all that clear which one is faster once JIT-compiled; I know Löve's one is damn fast. If LuaJIT's is more random, as you claim, it's probably because it spends more time generating better quality numbers, which means it will be slower. Nowadays most generators try to find a balance between quality, speed, memory and clarity, with some giving more weight to certain choices and others choosing differently.

Re: Random Generation map error on Mobile

Posted: Wed Aug 17, 2022 5:46 pm
by milon
owowow wrote: Tue Aug 16, 2022 6:47 pm And anyone knows if thats better use love.window.getSafeArea( ) instead of love.graphics.getWidth()/Height()?

Code: Select all

	safex, safey, safew, safeh = love.window.getSafeArea( )
    screensizex=safew
    screensizey=safeh
For desktop, there's absolutely no difference. On some mobile devices there's no difference. It will only be different if the mobile device in question has a "notch" in the screen - a part of the rectangular screen that can't be drawn to.

Personally, I use love.graphics.getWidth()/Height() when it comes to rendering the background, and love.window.getSafeArea() for any foreground stuff. That way you don't end up with black bars anywhere (or whatever you set the default color to), but the controls etc are guaranteed to be visible & accessible.

Re: Random Generation map error on Mobile

Posted: Thu Aug 18, 2022 5:09 pm
by owowow
Thanks all, I didn't expect that much people reacted to math.randam... After I changed it to love.math.random, it doesn't show the difference but it would be nice to know when the code went complicated.

About getSafeArea(), the main target is on mobile so I will have to take into consideration in the future.