mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-21 21:20:04 +00:00
restored getTime in rand gen
This commit is contained in:
parent
001a0b8d4b
commit
44fd66b511
12
src/Rand.cpp
12
src/Rand.cpp
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user