Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
kdbrand: elektraRandGetInitSeed behavior #1598
For the opmphm (a randomized hash map algorithm), a good and fast initialization seed is needed.
@markus2330 whats your opinion?
Opening /dev/urandom seems to be heavyweight within every key set. For an efficient solution using /dev/urandom we would need something like kdbksNew (similar to the idea with kdbKeyNew to use identity of the key name instead of hashing the string; kdb could then pool a bit of random data and give it to the next key sets).
But random(3) or the platform-specific arc4random (BSD specific) or getrandom (linux specific) might be better suited anyway.
For non-POSIX systems it is quite difficult. We could do a best-effort mixing of the sources available. time(0) seems to be the only info standardized in C99. In C11 timespec_get would be available. Then you could get two timestamps for and after some calculation which would also incorporate some random noise caused by the scheduler.
Maybe you can elaborate on how good the seed should be. Is it really a problem if different key sets get the same seed?