int generator
I currently generate deterministic pseudo-random ints 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);
The problem
There's two problems with this:
- The parameters for
Distributionmust beints. - The result from
Distribution(Mersenne)is anint.
The question
How do I generate a random long long instead of an int, with the Min and Max parameters also being long longs instead of ints?
The context
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 floats can cause non-determinism).
I won't accept answers that:
- Use
floats ordoubles - Suggest generating an
intand casting it to along long - Generate random numbers non-deterministically (i.e. mersenne is deterministic if the same seed is used)
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