diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Random.cpp | 15 | ||||
-rw-r--r-- | Source/Random.h | 16 | ||||
-rw-r--r-- | Source/Source.vcxproj | 1 | ||||
-rw-r--r-- | Source/Source.vcxproj.filters | 3 |
4 files changed, 24 insertions, 11 deletions
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 @@ | |||
1 | #include <chrono> | ||
2 | |||
3 | #include "Random.h" | ||
4 | |||
5 | int Random::s_seed = time(nullptr); // Seed from the time in milliseconds | ||
6 | |||
7 | void Random::SetSeed(int seed) { | ||
8 | s_seed = seed; | ||
9 | } | ||
10 | |||
11 | int Random::RandInt(int min, int max) { | ||
12 | s_seed = (214013 * s_seed + 2531011) % 2147483648; | ||
13 | if (min == max) return min; | ||
14 | return (s_seed % (max - (min - 1))) + min; | ||
15 | } | ||
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 | }; |
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 @@ | |||
174 | <ClCompile Include="Main.cpp" /> | 174 | <ClCompile Include="Main.cpp" /> |
175 | <ClCompile Include="Memory.cpp" /> | 175 | <ClCompile Include="Memory.cpp" /> |
176 | <ClCompile Include="Panel.cpp" /> | 176 | <ClCompile Include="Panel.cpp" /> |
177 | <ClCompile Include="Random.cpp" /> | ||
177 | <ClCompile Include="Randomizer.cpp" /> | 178 | <ClCompile Include="Randomizer.cpp" /> |
178 | <ClCompile Include="RandomizerCore.cpp" /> | 179 | <ClCompile Include="RandomizerCore.cpp" /> |
179 | </ItemGroup> | 180 | </ItemGroup> |
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 @@ | |||
53 | <ClCompile Include="Panel.cpp"> | 53 | <ClCompile Include="Panel.cpp"> |
54 | <Filter>Source Files</Filter> | 54 | <Filter>Source Files</Filter> |
55 | </ClCompile> | 55 | </ClCompile> |
56 | <ClCompile Include="Random.cpp"> | ||
57 | <Filter>Source Files</Filter> | ||
58 | </ClCompile> | ||
56 | </ItemGroup> | 59 | </ItemGroup> |
57 | <ItemGroup> | 60 | <ItemGroup> |
58 | <ResourceCompile Include="Version.rc"> | 61 | <ResourceCompile Include="Version.rc"> |