OpenClonk
C4Random.h File Reference
#include <cinttypes>
Include dependency graph for C4Random.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void FixedRandom (uint64_t dwSeed)
 
uint32_t Random (uint32_t iRange)
 
uint32_t UnsyncedRandom ()
 
uint32_t UnsyncedRandom (uint32_t range)
 
uint32_t SeededRandom (uint64_t iSeed, uint32_t iRange)
 
void RecordRandom (uint32_t range, uint32_t val)
 

Variables

int RandomCount
 

Function Documentation

◆ FixedRandom()

void FixedRandom ( uint64_t  dwSeed)

Definition at line 37 of file C4Random.cpp.

38 {
39  RandomRng.seed(seed);
40  RandomCount = 0;
41 }
int RandomCount
Definition: C4Random.cpp:27

Referenced by c4_random_handle_seed(), C4Game::FixRandom(), and main().

Here is the caller graph for this function:

◆ Random()

uint32_t Random ( uint32_t  iRange)

Definition at line 50 of file C4Random.cpp.

51 {
52  if (!iRange) return 0u;
53  uint32_t result = RandomRng(iRange);
54  RecordRandom(iRange, result);
55  return result;
56 }
void RecordRandom(uint32_t range, uint32_t val)

◆ RecordRandom()

void RecordRandom ( uint32_t  range,
uint32_t  val 
)

Definition at line 22 of file C4RandomRecord.cpp.

23 {
24  RandomCount++;
26  {
27  // next pseudorandom value
28  C4RCRandom rc;
29  rc.Cnt=RandomCount;
30  rc.Range=range;
31  rc.Val=val;
32  AddDbgRec(RCT_Random, &rc, sizeof(rc));
33  }
34 }
C4Config Config
Definition: C4Config.cpp:930
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
uint32_t Val
Definition: C4Record.h:144
@ RCT_Random
Definition: C4Record.h:58
uint32_t Range
Definition: C4Record.h:143
int32_t DebugRec
Definition: C4Config.h:63
C4ConfigGeneral General
Definition: C4Config.h:255

References AddDbgRec(), C4RCRandom::Cnt, Config, C4ConfigGeneral::DebugRec, C4Config::General, RandomCount, C4RCRandom::Range, RCT_Random, and C4RCRandom::Val.

Here is the call graph for this function:

◆ SeededRandom()

uint32_t SeededRandom ( uint64_t  iSeed,
uint32_t  iRange 
)

Definition at line 69 of file C4Random.cpp.

70 {
71  if (!iRange) return 0;
72  pcg32 rng(iSeed);
73  return rng(iRange);
74 }

Referenced by C4Sky::Init().

Here is the caller graph for this function:

◆ UnsyncedRandom() [1/2]

◆ UnsyncedRandom() [2/2]

uint32_t UnsyncedRandom ( uint32_t  range)

Definition at line 63 of file C4Random.cpp.

64 {
65  if (!iRange) return 0u;
66  return UnsyncedRandomRng(iRange);
67 }

Variable Documentation

◆ RandomCount

int RandomCount
extern

Definition at line 27 of file C4Random.cpp.

Referenced by RecordRandom().