diff options
| author | jbzdarkid <jbzdarkid@gmail.com> | 2018-11-05 07:21:05 -0800 |
|---|---|---|
| committer | jbzdarkid <jbzdarkid@gmail.com> | 2018-11-05 07:21:05 -0800 |
| commit | a2913485f2b072f0f3c531b9ef2e89ed066ec128 (patch) | |
| tree | 9a7c28fe5c48a63c11e27950c975149991e8dba8 /Source/Random.h | |
| parent | e48ce4469cee270687e04bc1a2b91d3c2bba0789 (diff) | |
| download | witness-tutorializer-a2913485f2b072f0f3c531b9ef2e89ed066ec128.tar.gz witness-tutorializer-a2913485f2b072f0f3c531b9ef2e89ed066ec128.tar.bz2 witness-tutorializer-a2913485f2b072f0f3c531b9ef2e89ed066ec128.zip | |
Fix RNG not changing
Diffstat (limited to 'Source/Random.h')
| -rw-r--r-- | Source/Random.h | 16 |
1 files changed, 5 insertions, 11 deletions
| 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 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | #include <chrono> | 2 | #include <typeinfo> |
| 3 | |||
| 4 | static int s_seed = time(nullptr); // Seed from the time in milliseconds | ||
| 5 | 3 | ||
| 6 | class Random | 4 | class Random |
| 7 | { | 5 | { |
| 8 | public: | 6 | public: |
| 9 | static void SetSeed(int seed) { | 7 | static void SetSeed(int seed); |
| 10 | s_seed = seed; | 8 | static int RandInt(int min, int max); |
| 11 | } | ||
| 12 | 9 | ||
| 13 | static int RandInt(int min, int max) { | 10 | private: |
| 14 | s_seed = (214013 * s_seed + 2531011) % 2147483648; | 11 | static int s_seed; |
| 15 | if (min == max) return min; | ||
| 16 | return (s_seed % (max - (min - 1))) + min; | ||
| 17 | } | ||
| 18 | }; | 12 | }; |
