As mentioned by @menaechmi, setting the random seed directly allows you to save and retrieve it for testing and debugging, in case you need to reproduce a random sequence. It can also be useful for gameplay features, like reproducing procedurally generated maps and other content – just save the seed and whatever other parameters you used. In such cases, automatically seeding the generator would get in the way, so it’s simpler to leave the API as it is.
Also, it’s been mentioned that separating the seeding and the generation is pretty standard in most languages / libraries, because it provides the aforementioned flexibility. Experienced programmers will expect this behavior. I guess that raises the broader question of how to decide between making things easier for more experienced programmers vs less experienced programmers.
Having math.random() not generate new patterns does not signal an experienced programmer…
Niether does your argument “reproducing procedurally generated maps” make sense. You save the seed and input it; I’ve created projects with procedurally generated maps with buildings. Nor testing and debugging makes sense- math.random()'s purpose is to deliver random numbers, not necessarily the same numbers.
You’re right about how it is generally- though once again- remember when everyone said the iPhone would never replace Blackberry or Nokia? Look where they’re at now. Usability of an Engine should always be the forefront or you will be superseded by other competition- but it is entirely up to the Defold team- it’s their baby not mine.
Having math.random() not generate new patterns does not signal an experienced programmer…
But following long-established conventions and preferring more flexible solutions does tend to go with experience.
Niether does your argument “reproducing procedurally generated maps” make sense. You save the seed and input it; I’ve created projects with procedurally generated maps with buildings. Nor testing and debugging makes sense- math.random()'s purpose is to deliver random numbers, not necessarily the same numbers.
To test and debug, the developer needs to reproduce the circumstances in which the bug was observed. Sometimes, those circumstances might involve a pseudo-random sequence – in that case, delivering the exact same sequence might be necessary in order to reproduce the bug or properly test the behavior. And I was trying to make a similar point with procedural content; you might want to re-create some content exactly, and re-using the same random seed is an easy way to do that.
What is there to test with math.random() library? At worst, just save the seed.
You’re essentially outlying ONE use case that will close to never be used by the masses- they want to develop games, not test a math.random library!
As there are multiple perspectives in design choice, I am currently Developing my project in Defold and GoDot at the same time.
I want an easy to develop engine where I’m not tinkering with the internals more than making the actual game- that is my personal interest. Perhaps your interest is something different, which is cool- you do you.
As you can see, if no seed is provided the default is “random”, so I get your confusion and I believe it could be done in the very same way, but in case of pseudo-random generators it was always on developer to decide which seed to provide, the program doesn’t assume it for us, it’s weird, I agree
Good discussions in this thread and some strong arguments for and against automatically seeding the random number generator in Defold. My take on this:
First the obvious statement that math.random() and math.randomseed() are functions provided by Lua, not by Defold. It is my strong opinion that Defold should not change the behavior of either of these functions. We should provide you with plain version of either Lua 5.1.4 (html5) or LuaJIT 2.1 (all other platforms). You should know exactly what you get.
Defold could do a call to math.randomseed(os.time()) “under the hood” at startup but there has so far not been any strong opinion for this kind of change.
Personally I don’t like things to happen “behind my back”. If we were to start seeding the Lua random number generator in Defold and I built my game based on this fact then I would not be able to run my game logic tests using a stand alone Lua version on CI for instance. I would also not be able to share Lua code on the client and a server for instance. In both of these scenarios I would need to manually seed the random number generator to get the same behavior as when running my code in Defold. Thus it makes more sense to never automatically seed the rng.