int
generatorI currently generate deterministic pseudo-random int
s using this code:
#include <chrono>
#include <ctime>
#include <random>
#include <stdint.h>
const uint32_t CurrentTime = static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count());
std::mt19937 Mersenne = std::mt19937(static_cast<std::mt19937::result_type>(CurrentTime));
int Min = 3;
int Max = 6;
std::uniform_int_distribution<> Distribution(Min, Max-1);
int Result = Distribution(Mersenne);
There's two problems with this:
Distribution
must be int
s.Distribution(Mersenne)
is an int
.How do I generate a random long long
instead of an int
, with the Min
and Max
parameters also being long long
s instead of int
s?
I'm creating a deterministic game (peer-to-peer architecture), and the large minimum-size of a long long
is needed as a sort of fixed-point number (since float
s can cause non-determinism).
I won't accept answers that:
float
s or double
sint
and casting it to a long long
I would much prefer a solution from the standard library if there is one.
Ideally, the solution should be at least as efficient as my existing code on a 64-bit machine.
the documentation says that the template parameter can be long long
long long Min = 3;
long long Max = 6;
std::uniform_int_distribution<long long> Distribution(Min, Max-1);
long long Result = Distribution(Mersenne);