Random Generation map error on Mobile

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Random Generation map error on Mobile

Post 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 :)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Random Generation map error on Mobile

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Random Generation map error on Mobile

Post 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.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: Random Generation map error on Mobile

Post 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.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
owowow
Prole
Posts: 7
Joined: Mon Aug 01, 2022 10:18 pm

Re: Random Generation map error on Mobile

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests