mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 05:20:05 +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 "Rand.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
std::unique_ptr<std::mt19937> Rand::generator;
|
std::unique_ptr<std::mt19937> Rand::generator;
|
||||||
|
|
||||||
int32_t Rand::rand(int32_t startInclusive, int32_t endExclusive) {
|
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) {
|
float Rand::randFloat(float endExclusive) {
|
||||||
std::uniform_real_distribution<float> dist(0.0f, endExclusive);
|
return Rand::randFloat(0.0f, endExclusive);
|
||||||
return dist(*Rand::generator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Rand::randFloat() {
|
float Rand::randFloat() {
|
||||||
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
|
return Rand::randFloat(0.0f, 1.0f);
|
||||||
return dist(*Rand::generator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rand::init() {
|
void Rand::init(uint64_t seed) {
|
||||||
// modern equivalent of srand(time(0))
|
|
||||||
uint64_t seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
|
|
||||||
Rand::generator = std::make_unique<std::mt19937>(std::mt19937(seed));
|
Rand::generator = std::make_unique<std::mt19937>(std::mt19937(seed));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
namespace Rand {
|
namespace Rand {
|
||||||
extern std::unique_ptr<std::mt19937> generator;
|
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 startInclusive, int32_t endExclusive);
|
||||||
int32_t rand(int32_t endExclusive);
|
int32_t rand(int32_t endExclusive);
|
||||||
|
@ -94,7 +94,7 @@ int main() {
|
|||||||
#else
|
#else
|
||||||
initsignals();
|
initsignals();
|
||||||
#endif
|
#endif
|
||||||
Rand::init();
|
Rand::init(getTime());
|
||||||
settings::init();
|
settings::init();
|
||||||
std::cout << "[INFO] OpenFusion v" GIT_VERSION << std::endl;
|
std::cout << "[INFO] OpenFusion v" GIT_VERSION << std::endl;
|
||||||
std::cout << "[INFO] Protocol version: " << PROTOCOL_VERSION << std::endl;
|
std::cout << "[INFO] Protocol version: " << PROTOCOL_VERSION << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user