27 #include <QRandomGenerator>
29 #define log_rand log_debug
38 static std::mt19937 generator = std::mt19937();
48 const char *called_as,
int line,
58 std::uniform_int_distribution<std::uint_fast32_t> uniform(0,
size - 1);
60 auto random = uniform(generator);
61 qCDebug(random_category,
"%s(%lu) = %lu at %s:%d", called_as,
62 (
unsigned long)
size, (
unsigned long) random, file, line);
91 struct random_seed_seq {
95 template <
typename It>
void generate(It begin, It end)
97 for (; begin != end; ++begin) {
98 *begin = qgenerator();
103 using result_type = decltype(QRandomGenerator64{}.generate());
106 QRandomGenerator64 qgenerator = QRandomGenerator64::securelySeeded();
115 auto seed = random_seed_seq();
143 std::uint_fast32_t
size,
144 const char *called_as,
int line,
147 std::uint_fast32_t result;
149 #define LARGE_PRIME (10007)
150 #define SMALL_PRIME (1009)
158 log_rand(
"%s(%lu,%lu) = %lu at %s:%d", called_as, (
unsigned long) seed,
159 (
unsigned long)
size, (
unsigned long) result, file, line);
#define fc_assert_ret_val(condition, val)
void fc_rand_set_init(bool init)
Sets whether the current state has been initialized.
std::mt19937 & fc_rand_state()
Returns a reference to the current random generator state; eg for save/restore.
void fc_rand_set_state(const std::mt19937 &state)
Replace current rand_state with user-supplied; eg for save/restore.
std::uint_fast32_t fc_randomly_debug(std::uint_fast32_t seed, std::uint_fast32_t size, const char *called_as, int line, const char *file)
Local pseudo-random function for repeatedly reaching the same result, instead of fc_rand().
bool fc_rand_is_init()
Return whether the current state has been initialized.
void fc_srand(std::uint_fast32_t seed)
Initialize the generator; see comment at top of file.
std::uint_fast32_t fc_rand_debug(std::uint_fast32_t size, const char *called_as, int line, const char *file)
Returns a new random value from the sequence, in the interval 0 to (size-1) inclusive,...
void fc_rand_seed(std::mt19937 &gen)
Seeds the given generator with a random value.
Q_LOGGING_CATEGORY(tileset_category, "freeciv.tileset")
Functions for handling the tilespec files which describe the files and contents of tilesets.