From 44fd66b5117001935d89f2f4fd22daa8e2c2bb17 Mon Sep 17 00:00:00 2001 From: FinnHornhoover Date: Sun, 4 Apr 2021 03:41:04 -0700 Subject: [PATCH] restored getTime in rand gen --- src/Rand.cpp | 12 +++--------- src/Rand.hpp | 2 +- src/main.cpp | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Rand.cpp b/src/Rand.cpp index f92dc75..bc0b3c3 100644 --- a/src/Rand.cpp +++ b/src/Rand.cpp @@ -1,7 +1,5 @@ #include "Rand.hpp" -#include - std::unique_ptr Rand::generator; int32_t Rand::rand(int32_t startInclusive, int32_t endExclusive) { @@ -28,17 +26,13 @@ float Rand::randFloat(float startInclusive, float endExclusive) { } float Rand::randFloat(float endExclusive) { - std::uniform_real_distribution dist(0.0f, endExclusive); - return dist(*Rand::generator); + return Rand::randFloat(0.0f, endExclusive); } float Rand::randFloat() { - std::uniform_real_distribution dist(0.0f, 1.0f); - return dist(*Rand::generator); + return Rand::randFloat(0.0f, 1.0f); } -void Rand::init() { - // modern equivalent of srand(time(0)) - uint64_t seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); +void Rand::init(uint64_t seed) { Rand::generator = std::make_unique(std::mt19937(seed)); } diff --git a/src/Rand.hpp b/src/Rand.hpp index 4240910..1c770e2 100644 --- a/src/Rand.hpp +++ b/src/Rand.hpp @@ -6,7 +6,7 @@ namespace Rand { extern std::unique_ptr generator; - void init(); + void init(uint64_t seed); int32_t rand(int32_t startInclusive, int32_t endExclusive); int32_t rand(int32_t endExclusive); diff --git a/src/main.cpp b/src/main.cpp index 6a7eca6..c4ccb10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,7 +94,7 @@ int main() { #else initsignals(); #endif - Rand::init(); + Rand::init(getTime()); settings::init(); std::cout << "[INFO] OpenFusion v" GIT_VERSION << std::endl; std::cout << "[INFO] Protocol version: " << PROTOCOL_VERSION << std::endl;