Freeciv21
Develop your civilization from humble roots to a global empire
rand.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 #include <random>
14 #include <stdint.h>
15 
16 #define fc_rand(_size) fc_rand_debug((_size), "fc_rand", __LINE__, __FILE__)
17 
18 std::uint_fast32_t fc_rand_debug(std::uint_fast32_t size,
19  const char *called_as, int line,
20  const char *file);
21 
22 void fc_srand(std::uint_fast32_t seed);
23 void fc_rand_seed(std::mt19937 &gen);
24 
25 bool fc_rand_is_init();
26 void fc_rand_set_init(bool init);
27 
28 std::mt19937 &fc_rand_state();
29 void fc_rand_set_state(const std::mt19937 &state);
30 
31 /*===*/
32 
33 #define fc_randomly(_seed, _size) \
34  fc_randomly_debug((_seed), (_size), "fc_randomly", __LINE__, __FILE__)
35 
36 std::uint_fast32_t fc_randomly_debug(std::uint_fast32_t seed,
37  std::uint_fast32_t size,
38  const char *called_as, int line,
39  const char *file);
bool init
Definition: mapimg.cpp:328
void fc_rand_set_init(bool init)
Sets whether the current state has been initialized.
Definition: rand.cpp:83
std::mt19937 & fc_rand_state()
Returns a reference to the current random generator state; eg for save/restore.
Definition: rand.cpp:123
void fc_rand_set_state(const std::mt19937 &state)
Replace current rand_state with user-supplied; eg for save/restore.
Definition: rand.cpp:129
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().
Definition: rand.cpp:142
bool fc_rand_is_init()
Return whether the current state has been initialized.
Definition: rand.cpp:78
void fc_srand(std::uint_fast32_t seed)
Initialize the generator; see comment at top of file.
Definition: rand.cpp:69
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,...
Definition: rand.cpp:47
void fc_rand_seed(std::mt19937 &gen)
Seeds the given generator with a random value.
Definition: rand.cpp:113
size_t size
Definition: specvec.h:64