Skip to main content
deleted 4 characters in body
Source Link
undercat
  • 1.9k
  • 1
  • 13
  • 19

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() often has a granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run, or use /dev/random.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() often has a granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run, or use /dev/random.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() often has a granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run, or use /dev/random.

Alternatively, if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

added 20 characters in body
Source Link
undercat
  • 1.9k
  • 1
  • 13
  • 19

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() often has a granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run, or use /dev/random.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() often has a granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() often has a granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run, or use /dev/random.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

added 8 characters in body
Source Link
undercat
  • 1.9k
  • 1
  • 13
  • 19

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() usuallyoften has a certain granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() usually has a certain granularity, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

Can it technically occur that the same random seed is taken?

If you look at the function you linked, you will see that it uses the number of microseconds as the seed (modulo 10^6):

void Random::InitRandom(int seed)   {

    if (seed == -1) {
        struct timeval tod;
        gettimeofday(&tod, NULL);
        seed = tod.tv_usec; // <== this line
    }
    Seed = seed;
    srand(seed);
    ...
}

So, yes, if two instances of your software run that function on the same microsecond (or perhaps with an exactly 1 second difference, etc), you will get the same seed. That is plausible because you launch one instance immediately after another.

This is further aggravated by the fact that gettimeofday() often has a granularity coarser than 1 μs, so runs that happen very close to each other in time may have the same tv_usec value even if they don't occur on the exact same microsecond.

I think the best way to fix this is to build your own version with a different seed initialization algorithm that suits the way you use the software. E.g. instead of using microseconds, you can just increase the seed number by 1 on each subsequent run.

Alternatively, you if you have GNU coreutils, you can use the sleep 0.001 command to pause the second execution for 1 millisecond, that should introduce the delay that should be sufficient for different instances to have different seeds.

added 238 characters in body
Source Link
undercat
  • 1.9k
  • 1
  • 13
  • 19
Loading
Source Link
undercat
  • 1.9k
  • 1
  • 13
  • 19
Loading