OpenTTD Source 20241224-master-gf74b0cf984
Randomizer Struct Reference

Structure to encapsulate the pseudo random number generators. More...

#include <random_func.hpp>

Public Member Functions

uint32_t Next ()
 Generate the next pseudo random number.
 
void SetSeed (uint32_t seed)
 (Re)set the state of the random number generator.
 
uint32_t Next (uint32_t limit)
 Generate the next pseudo random number scaled to limit, excluding limit itself.
 

Data Fields

uint32_t state [2]
 The state of the randomizer.
 

Detailed Description

Structure to encapsulate the pseudo random number generators.

Definition at line 27 of file random_func.hpp.

Member Function Documentation

◆ Next() [1/2]

uint32_t Randomizer::Next ( )

Generate the next pseudo random number.

Returns
the random number

Definition at line 43 of file random_func.cpp.

References state.

Referenced by CmdBuildIndustry(), GenerateTownName(), and RandomCompanyManagerFaceBits().

◆ Next() [2/2]

uint32_t Randomizer::Next ( uint32_t  limit)
inline

Generate the next pseudo random number scaled to limit, excluding limit itself.

Parameters
limitLimit of the range to be generated from.
Returns
Random number in [0,limit)

Definition at line 40 of file random_func.hpp.

References Next(), and ScaleToLimit().

Referenced by Next().

◆ SetSeed()

void Randomizer::SetSeed ( uint32_t  seed)

(Re)set the state of the random number generator.

Parameters
seedthe new state

Definition at line 56 of file random_func.cpp.

References state.

Referenced by _GenerateWorld(), CmdBuildIndustry(), and SetRandomSeed().

Field Documentation

◆ state

uint32_t Randomizer::state[2]

The state of the randomizer.

Definition at line 29 of file random_func.hpp.

Referenced by ClientNetworkGameSocketHandler::GameLoop(), Next(), and SetSeed().


The documentation for this struct was generated from the following files: