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

Use current time instead of hardcoded value as random seed #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xV8IHmeZIAStqNFV8iKGyyertVIet15TS6gWrIV

Currently, the random seed is hard coded to be 0x1234567, which leads to the output being exactly the same every time you reset it by pressing the space bar.

@@ -95,7 +95,7 @@ void Cloud::Reset() {
droplet.Reset();

// Reset all the RNG stuff
mt.seed(0x1234567);
mt.seed(high_resolution_clock::now().time_since_epoch().count());
Copy link
Owner

@st3w st3w Dec 23, 2021

Choose a reason for hiding this comment

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

Hello @xV8IHmeZIAStqNFV8iKGyyertVIet15TS6gWrIV,

tl;dr Add a static_cast<uint32_t>, and this should be fine.

I made this deterministic to make it easier to debug things during development. I have no objections to making it truly random now.

However, count() will return a 64-bit unsigned integer, but seed() takes a 32-bit unsigned integer (mt19937 takes a 32-bit seed, mt19937_64 takes a 64-bit seed). So some compilers will warn that this operation performs an implicit narrowing conversion. If you add a static_cast<uint32_t>, then it will be fine.

A better approach would be something like:

random_device rd;
seed_seq sseq{rd(), rd()}; // 64-bits of random state used for seeding
mt.seed(sseq);

Edit: Also, I will be away from my development computer until Jan 10th. So this won't get merged for a while...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants