-
Notifications
You must be signed in to change notification settings - Fork 391
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
Initialize srand with hostname and PID #738
Conversation
Claude suggested this: unsigned int generate_seed() {
unsigned int seed = (unsigned int)time(NULL);
seed ^= (unsigned int)clock();
seed ^= (unsigned int)getpid();
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
seed ^= (unsigned int)ts.tv_nsec;
}
return seed;
} WDYS? |
I don't think we gain from mixing 3 different time-based values ( However, But a suggestion like this would almost definitely solve my problem too :) |
Sounds good. So can you implement it? |
d350b32
to
bfe53a2
Compare
Yep, updated to XOR with the nanosecond value too :) |
Any idea why the test fails? |
Rebased and it passed. Merging. Thanks for your persistence @FalacerSelene! |
We're running SIPp in a container scaleset, and ran into an issue where two instances started in the same second and continually picked the same random numbers as each other, which meant that
InputFileRandomOrder
actually had the instances continually 'randomly' picking the same entries.To avoid this, this change adds a bit more noise to the start-of-day call to
srand()
, mixing in the PID and the hostname, which would avoid two instances using the same seed.I'd welcome an alternative and better way to do this!