Skip to content
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

Fix setting random seed to current time #2651

Merged
merged 3 commits into from
Oct 5, 2023

Conversation

Vankata453
Copy link
Member

Setting the random seed to 0 or lower of a Random generator will now set it to the UNIX timestamp of the current time.

Setting the random seed to 0 or lower of a `Random` generator will now set it to the UNIX timestamp of the current time.
@Vankata453 Vankata453 added category:code status:needs-review Work needs to be reviewed by other people type:bugfix Pull Requests that fix bugs. labels Sep 30, 2023
@tobbi
Copy link
Member

tobbi commented Oct 2, 2023

Users/runner/work/supertux/supertux/src/math/random.cpp:36:22: error: implicit conversion loses integer precision: 'time_t' (aka 'long') to 'std::mersenne_twister_engine<unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
    m_generator.seed(std::time(nullptr));

@mrkubax10 mrkubax10 requested a review from tobbi October 3, 2023 19:39
Copy link
Member

@tobbi tobbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, although you could've just assigned to v directly without that return.

@mrkubax10
Copy link
Member

Yeah, although you could've just assigned to v directly without that return.

True

@Vankata453
Copy link
Member Author

Vankata453 commented Oct 3, 2023

Yeah, although you could've just assigned to v directly without that return.

Indeed, realized that later, but I thought it's still better to directly cast to unsigned int.

@Vankata453 Vankata453 merged commit 6bbfb45 into SuperTux:master Oct 5, 2023
33 checks passed
@Vankata453 Vankata453 deleted the fix-random-seed branch October 5, 2023 09:47
@mrkubax10 mrkubax10 removed the status:needs-review Work needs to be reviewed by other people label Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:code type:bugfix Pull Requests that fix bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants