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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...


int8_t lowPair, highPair;
if (_numColorPairs < 3) {
Expand Down