From: Steve Brokenshire Date: Mon, 17 Jul 2017 19:50:24 +0000 (+0100) Subject: random: Implemented Win32 version X-Git-Tag: release-0.04~10 X-Git-Url: http://Server1/repobrowser/?p=xestiacalendar%2F.git;a=commitdiff_plain;h=fcc4024e7e27ed30e444cbf811671a3a7f41471d random: Implemented Win32 version --- 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