-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
array.shuffle() does not work properly #28689
Comments
That is expected behaviour. If you want to get random values each time you run the game you should use the function A note could be added to the docs pointing users to |
Thanks for pointing me to randomize() Should I close the issue now or after the docs gets updated? By the way I tried updating the docs, I press on the button " Edit on GitHub" Takes me to 404 page https://github.com/godotengine/godot-docs-l10n/blob/master/docs/classes/class_array.rst That needs to be fixed too, either remove the button or the hyperlink should be fixed. |
You should close it after the docs get updated. |
Should there just be a whole page in the docs describing how RNG works and how seeds/randomize work? I've seen similar issues of people reporting random things being exactly the same every time they run their game, and it's because they haven't randomized or set a seed. |
By the way why not randomize the seed by default? what is the benefit of not doing that? doesn't that become predictable and thus as if one never used array.shuffle() at all? I mean what is the point of having a shuffle that can't 'shuffle'. If Something isn't random, it isn't shuffled, so why shuffle doesn't call randomize by default? |
@CowThing That is a good idea, it would be a welcome addition. You should make an issue in the godot-docs repo and if you have time maybe put together a PR. It would be a good tutorial to put in the math section.
@elieobeid7 Oftentimes what you want when using randomness is to have a different result each time the function is called rather than a different result each time the game is run. This is especially the case for games that use procedural generation. You want to reliably generate the same data each run.
It is still randomized, its just the same random sequence each run. If you run array.shuffle() multiple times in the same run it will return a different order each time. Computers actually cannot produce 'random' numbers. All random number generation is actually psuedo random number generation. It takes a seed as input and produces a seemingly random set of results as output. This is how nearly all RNG works on computers except for high-tech cryptography algorithms and such. |
@clayjohn But there is the Unless I'm having a giant brain fart, It would be preferable imo to randomize the core random functions on startup and have the user use their own Also, |
I don't see why that would be a problem. But I also have no preference for the default behaviour. I'm just stating the current behaviour. 🤷♂
Thats a good idea! It just isn't the way things work now. Good idea for a PR! |
Should have phrased this better! I meant that any unforseen call to rand will mess your pattern (user input, threading, etc). It's only a problem if you need the pattern to be the same in all runs (think of procedurally generating a world), in which case I think you don't have a choice but to use I don't have a preference either, but the argument against randomizing on startup is good for simulation softwares, not so much for a game engine I think. |
Fixed by #28832. |
https://godot.readthedocs.io/uk/latest/classes/class_array.html#class-array-method-shuffle
if you use that, you restarted your game, from the editor, you will have the same values over and over again.
The text was updated successfully, but these errors were encountered: