Skip to content

Possible bug in random root seed generation #21

@ricardocannizzaro

Description

@ricardocannizzaro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions