int
generator
I 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);
The problem
There's two problems with this:
- The parameters for
Distribution
must beint
s. - 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 long
s instead of int
s?
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 float
s can cause non-determinism).
I won't accept answers that:
- Use
float
s ordouble
s - Suggest generating an
int
and 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.