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

Possible bug in random root seed generation #21

Open
ricardocannizzaro opened this issue Nov 14, 2022 · 0 comments
Open

Possible bug in random root seed generation #21

ricardocannizzaro opened this issue Nov 14, 2022 · 0 comments

Comments

@ricardocannizzaro
Copy link

ricardocannizzaro commented Nov 14, 2022

Hi,

Thanks for the great repo!

I think I have found a possible bug with generating the pseudo-random random root seed:

long millis = (long) get_time_second() * 1000;

This casts the result of get_time_second() to long before the x1000 operation, so the millisecond component is lost before the multiplication, resulting in the seeds always having 000 as the final 3 digits. I don't believe this is the intended behaviour because it should use the 3-digit millisecond component in the generated seed.

Putting additional parenthesis around the calculation to delay the cast to long to the end seems to fix the problem:

long millis = (long) (get_time_second() * 1000);

I have provided example executions below, run on Ubuntu 20.04.

Original output:

gettimeofday ran with tv_sec: 1668419612, tv_usec: 610524
Generated random root seed 419612000. millis: 1668419612000, range: 1000000000

After fix:

gettimeofday ran with tv_sec: 1668419694, tv_usec: 729435
Generated random root seed 419694729. millis: 1668419694729, range: 1000000000

Cheers!
Ricardo

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

No branches or pull requests

1 participant