-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Replace random_shuffle with std::shuffle #5463
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
Replace random_shuffle with std::shuffle #5463
Conversation
std::random_shuffle has been deprecated since c++14. this is my attempt at replacing it |
src/utils/random_generator.cpp
Outdated
return generator; | ||
} | ||
|
||
unsigned int RandomGenerator::m_random_value = RandomGenerator::default_seed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's initialization of m_random_value since it's static. however, i realized that m_random_value = default_seed in the constructor was not necessary so i removed it. i then replaced the ctor with a default. new commit pushed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe i misunderstood the question. do you mean what the default_seed is used for? only to check if a seed was provided from the command line or not. if no seed is provided, the random generator will be initialized like this: std::mt19937{std::random_device{}()}, so the default_seed will never actually be used as a seed
I don't know this code so maybe it doesn't matter, just note that any changes in random generator may affect network multiplayer. |
regarding the comment from @deveee regarding network multiplayer, i don't think it is affected yet. there are hints in this comment in random_generator.hpp: "// This generator is (currently) not good enough, i.e. it often gives |
How the numbers are generated matters for networked play, because the client may not get the authoritative data from the server for 50-200ms depending on ping. However, RNG for powerups picked from gift boxes uses a special system, so as to make client-side prediction effective. The relevant code can be seen from here on: stk-code/src/items/powerup.cpp Line 552 in 6260dc8
I also had concerns about potential compatibility issues, but from what I can tell most uses from this random generator are for things such as giving a random track when picking the random track button. The one exception is picking nodes to spawn tire karts in 3-strikes battle, but online is FFA instead of 3 strikes anyways. |
Agreement