Freeciv21
Develop your civilization from humble roots to a global empire
rand.cpp File Reference

The following random number generator is a simple wrapper around the C++ standard library. More...

#include "log.h"
#include "rand.h"
#include "shared.h"
#include <QRandomGenerator>
+ Include dependency graph for rand.cpp:

Go to the source code of this file.

Macros

#define log_rand   log_debug
 
#define LARGE_PRIME   (10007)
 
#define SMALL_PRIME   (1009)
 

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...
 
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...
 
void fc_rand_seed (std::mt19937 &gen)
 Seeds the given generator with a random value. 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...
 

Detailed Description

The following random number generator is a simple wrapper around the C++ standard library.

Definition in file rand.cpp.

Macro Definition Documentation

◆ LARGE_PRIME

#define LARGE_PRIME   (10007)

◆ log_rand

#define log_rand   log_debug

Definition at line 29 of file rand.cpp.

◆ SMALL_PRIME

#define SMALL_PRIME   (1009)

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