aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Support/Process.h6
-rw-r--r--lib/Support/Process.cpp9
2 files changed, 14 insertions, 1 deletions
diff --git a/include/llvm/Support/Process.h b/include/llvm/Support/Process.h
index d796b7906d..91b92788f2 100644
--- a/include/llvm/Support/Process.h
+++ b/include/llvm/Support/Process.h
@@ -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();
/// @}
};
}
diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp
index 88ca7c3f22..c65cb45404 100644
--- a/lib/Support/Process.cpp
+++ b/lib/Support/Process.cpp
@@ -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.