mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
Unix/Process.inc: Give more useful random seed to srand. Workaround for PR12743.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156252 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
24cddd5c9a
commit
dc736b0a3e
@ -298,11 +298,24 @@ const char *Process::ResetColor() {
|
||||
return "\033[0m";
|
||||
}
|
||||
|
||||
#if !defined(HAVE_ARC4RANDOM)
|
||||
static unsigned GetRandomNumberSeed() {
|
||||
unsigned seed = ::time(NULL); // FIXME: It might not provide unique seed.
|
||||
FILE *RandomSource = ::fopen("/dev/urandom", "r");
|
||||
if (RandomSource) {
|
||||
::fread((void *)&seed, sizeof(seed), 1, RandomSource);
|
||||
::fclose(RandomSource);
|
||||
}
|
||||
return seed;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned llvm::sys::Process::GetRandomNumber() {
|
||||
#if defined(HAVE_ARC4RANDOM)
|
||||
return arc4random();
|
||||
#else
|
||||
static int x = (::srand(::time(NULL)), 0);
|
||||
static int x = (::srand(GetRandomNumberSeed()), 0);
|
||||
(void)x;
|
||||
return ::rand();
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user