From fcc4024e7e27ed30e444cbf811671a3a7f41471d Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 17 Jul 2017 20:50:24 +0100 Subject: [PATCH] random: Implemented Win32 version --- source/common/random.cpp | 13 +++++++++++-- source/common/random.h | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/common/random.cpp b/source/common/random.cpp index ff0b619..40316c6 100644 --- a/source/common/random.cpp +++ b/source/common/random.cpp @@ -21,7 +21,16 @@ using namespace std; int GenerateRandomNumber(int powerOf){ - +#if defined(WIN32) + + // Seed the randomiser! + + srand(time(0)); + + int powerOfCalculation = (int)pow(2, (double)powerOf); + int randomNumber = rand() % powerOfCalculation; + +#else // Get four bytes from /dev/urandom. int randomData = 0; @@ -41,7 +50,7 @@ int GenerateRandomNumber(int powerOf){ int powerOfCalculation = (int)pow(2, (double)powerOf); int randomNumber = rand() % powerOfCalculation; +#endif return randomNumber; - } \ No newline at end of file diff --git a/source/common/random.h b/source/common/random.h index a931eeb..390d9af 100644 --- a/source/common/random.h +++ b/source/common/random.h @@ -24,6 +24,11 @@ #include #include +#if defined(WIN32) +#include +#include +#endif + int GenerateRandomNumber(int powerOf); #endif \ No newline at end of file -- 2.39.2