mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-14 07:09:08 +00:00
[Support] Add sys::Process::GetRandomNumber().
- Primitive API, but we rarely have need for random numbers. llvm-svn: 156237
This commit is contained in:
parent
c69f7c9234
commit
457eab2ad7
@ -1,4 +1,4 @@
|
||||
//===- llvm/Support/Process.h ------------------------------------*- C++ -*-===//
|
||||
//===- llvm/Support/Process.h -----------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
@ -142,6 +142,10 @@ namespace sys {
|
||||
|
||||
/// Resets the terminals colors, or returns an escape sequence to do so.
|
||||
static const char *ResetColor();
|
||||
|
||||
/// Get the result of a process wide random number generator. The
|
||||
/// generator will be automatically seeded in non-deterministic fashion.
|
||||
static unsigned GetRandomNumber();
|
||||
/// @}
|
||||
};
|
||||
}
|
||||
|
@ -22,6 +22,15 @@ using namespace sys;
|
||||
//=== independent code.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
unsigned llvm::sys::Process::GetRandomNumber() {
|
||||
#if defined(HAVE_ARC4RANDOM)
|
||||
return arc4random();
|
||||
#else
|
||||
static int x = (::srand(::time(NULL)), 0);
|
||||
return rand();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Include the platform-specific parts of this class.
|
||||
|
Loading…
Reference in New Issue
Block a user