AdaCompNUS/despot

Possible bug in random root seed generation

ricardocannizzaro opened this issue · 0 comments

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