Freeciv21
Develop your civilization from humble roots to a global empire
rand.h File Reference
#include <random>
#include <stdint.h>
+ Include dependency graph for rand.h:

Go to the source code of this file.

Macros

#define fc_rand(_size)   fc_rand_debug((_size), "fc_rand", __LINE__, __FILE__)
 
#define fc_randomly(_seed, _size)    fc_randomly_debug((_seed), (_size), "fc_randomly", __LINE__, __FILE__)
 

Functions

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, and updates global state for next call. More...
 
void fc_srand (std::uint_fast32_t seed)
 Initialize the generator; see comment at top of file. More...
 
void fc_rand_seed (std::mt19937 &gen)
 Seeds the given generator with a random value. More...
 
bool fc_rand_is_init ()
 Return whether the current state has been initialized. More...
 
void fc_rand_set_init (bool init)
 Sets whether the current state has been initialized. More...
 
std::mt19937 & fc_rand_state ()
 Returns a reference to the current random generator state; eg for save/restore. More...
 
void fc_rand_set_state (const std::mt19937 &state)
 Replace current rand_state with user-supplied; eg for save/restore. More...
 
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(). More...
 

Macro Definition Documentation

◆ fc_rand

#define fc_rand (   _size)    fc_rand_debug((_size), "fc_rand", __LINE__, __FILE__)

Definition at line 16 of file rand.h.

◆ fc_randomly

#define fc_randomly (   _seed,
  _size 
)     fc_randomly_debug((_seed), (_size), "fc_randomly", __LINE__, __FILE__)

Definition at line 33 of file rand.h.

Function Documentation

◆ fc_rand_debug()

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, and updates global state for next call.

This means that if size <= 1 the function will always return 0.

Definition at line 47 of file rand.cpp.

◆ fc_rand_is_init()

bool fc_rand_is_init ( )

Return whether the current state has been initialized.

Definition at line 78 of file rand.cpp.

◆ fc_rand_seed()

void fc_rand_seed ( std::mt19937 &  gen)

Seeds the given generator with a random value.

Definition at line 113 of file rand.cpp.

Referenced by init_game_seed(), map_generate(), and sg_load_random().

◆ fc_rand_set_init()

void fc_rand_set_init ( bool  init)

Sets whether the current state has been initialized.

Definition at line 83 of file rand.cpp.

Referenced by fc_rand_set_state(), fc_srand(), init_game_seed(), and freeciv::server::shut_game_down().

◆ fc_rand_set_state()

void fc_rand_set_state ( const std::mt19937 &  state)

Replace current rand_state with user-supplied; eg for save/restore.

Caller should take care to set state.is_init beforehand if necessary.

Definition at line 129 of file rand.cpp.

Referenced by map_generate(), sg_load_random(), and sg_load_sanitycheck().

◆ fc_rand_state()

std::mt19937& fc_rand_state ( )

Returns a reference to the current random generator state; eg for save/restore.

Definition at line 123 of file rand.cpp.

Referenced by genlist_shuffle(), init_game_seed(), loaddata_new(), map_generate(), sg_load_random(), and sg_save_random().

◆ fc_randomly_debug()

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().

Primarily needed for tiles.

Use an invariant equation for seed. Result is 0 to (size - 1).

Definition at line 142 of file rand.cpp.

◆ fc_srand()

void fc_srand ( std::uint_fast32_t  seed)

Initialize the generator; see comment at top of file.

Definition at line 69 of file rand.cpp.

Referenced by client_main(), fcmp_init(), init_game_seed(), and map_generate().