restored getTime in rand gen

This commit is contained in:
FinnHornhoover 2021-04-04 03:41:04 -07:00 committed by Gent Semaj
parent 001a0b8d4b
commit 44fd66b511
3 changed files with 5 additions and 11 deletions

View File

@ -1,7 +1,5 @@
#include "Rand.hpp"
#include <chrono>
std::unique_ptr<std::mt19937> 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<float> dist(0.0f, endExclusive);
return dist(*Rand::generator);
return Rand::randFloat(0.0f, endExclusive);
}
float Rand::randFloat() {
std::uniform_real_distribution<float> 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>(std::mt19937(seed));
}

View File

@ -6,7 +6,7 @@
namespace Rand {
extern std::unique_ptr<std::mt19937> generator;
void init();
void init(uint64_t seed);
int32_t rand(int32_t startInclusive, int32_t endExclusive);
int32_t rand(int32_t endExclusive);

View File

@ -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;