From a2913485f2b072f0f3c531b9ef2e89ed066ec128 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Mon, 5 Nov 2018 07:21:05 -0800 Subject: Fix RNG not changing --- Source/Random.cpp | 15 +++++++++++++++ Source/Random.h | 16 +++++----------- Source/Source.vcxproj | 1 + Source/Source.vcxproj.filters | 3 +++ 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 Source/Random.cpp (limited to 'Source') diff --git a/Source/Random.cpp b/Source/Random.cpp new file mode 100644 index 0000000..cc3eb6c --- /dev/null +++ b/Source/Random.cpp @@ -0,0 +1,15 @@ +#include + +#include "Random.h" + +int Random::s_seed = time(nullptr); // Seed from the time in milliseconds + +void Random::SetSeed(int seed) { + s_seed = seed; +} + +int Random::RandInt(int min, int max) { + s_seed = (214013 * s_seed + 2531011) % 2147483648; + if (min == max) return min; + return (s_seed % (max - (min - 1))) + min; +} diff --git a/Source/Random.h b/Source/Random.h index 40998de..179f0fa 100644 --- a/Source/Random.h +++ b/Source/Random.h @@ -1,18 +1,12 @@ #pragma once -#include - -static int s_seed = time(nullptr); // Seed from the time in milliseconds +#include class Random { public: - static void SetSeed(int seed) { - s_seed = seed; - } + static void SetSeed(int seed); + static int RandInt(int min, int max); - static int RandInt(int min, int max) { - s_seed = (214013 * s_seed + 2531011) % 2147483648; - if (min == max) return min; - return (s_seed % (max - (min - 1))) + min; - } +private: + static int s_seed; }; diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index 020f69b..4319a91 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -174,6 +174,7 @@ + diff --git a/Source/Source.vcxproj.filters b/Source/Source.vcxproj.filters index 8f94061..f480c6c 100644 --- a/Source/Source.vcxproj.filters +++ b/Source/Source.vcxproj.filters @@ -53,6 +53,9 @@ Source Files + + Source Files + -- cgit 1.4.1