Describe the project you are working on:
Godot Engine.
Describe the problem or limitation you are having in your project:
I don't, but users do:
I can likely find a bunch of other examples.
I recall stumbling upon the same limitation when I first started using the engine (like 4 years ago), with mostly lack of programming experience. So, I think this is mostly confusing to beginners.
See also #1590:
The global RNG has to be randomized implicitly, as in many other scripting programming languages.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Call randomize() in the engine automatically for global RNG, so this is mostly about GDScript and built-in Math::random() usages in the engine. This should not affect local instances of RandomNumberGenerator classes.
Tests in C++ should use RandomNumberGenerator locally instantiated for reproducible random results (for stress tests), and of course in GDScript for similar use cases if you do need to control the seed, like procedural generation.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
It's a matter of calling randomize() somewhere in the engine. This breaks compatibility, but it's the perfect time for Godot 4.0.
If this enhancement will not be used often, can it be worked around with a few lines of script?:
Sure, just call randomize() in GDScript.
Is there a reason why this should be core and not an add-on in the asset library?:
Already part of core.
I know this is done for the purposes of debugging games -- it makes it easier to replicate results.
That said, I wouldn't be against this being a Project Setting. It seems like a fairly reasonable setting to add.
That said, I wouldn't be against this being a Project Setting.
I agree because the RNG in Godot is not the only one out there, and other implementations can reuse the same project setting (in plugins and modules). But I know for sure that Godot is allergic to adding potentially "specific" settings, so I'd be personally happy with any decision. But one also have to take into account the amount of confusion this currently creates for beginners. 馃檪
The new setting could be added in application/run/randomize_rng or something like that. And obviously, I propose to have it enabled by default.
I think we should always do this. There's no need to add a project setting. For people who need determinism, they can create their own RandomNumberGenerator instance and set the seed manually.
You don't even need RandomNumberGenerator, just call seed() when you need determinism.
Most helpful comment
You don't even need RandomNumberGenerator, just call
seed()when you need determinism.