OpenTTD Source: Randomizer Struct Reference

OpenTTD Source 13.2.1

Public Member Functions | Data Fields
Randomizer Struct Reference

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

`#include <random_func.hpp>`

## Public Member Functions
uint32 | Next ()
| Generate the next pseudo random number. More...
uint32 | Next (uint32 limit)
| Generate the next pseudo random number scaled to limit, excluding limit itself. More...
void | SetSeed (uint32 seed)
| (Re)set the state of the random number generator. More...

## Data Fields
uint32 | state [2]
| The state of the randomizer.

## Detailed Description

Structure to encapsulate the pseudo random number generators.

Definition at line 21 of file random_func.hpp.

## Member Function Documentation

## ◆ Next() [1/2]

uint32 Randomizer::Next | ( |  | ) |

Generate the next pseudo random number.

Returns
  the random number

Definition at line 31 of file random_func.cpp.

References ROR(), and state.

Referenced by Next(), and RandomRange().

## ◆ Next() [2/2]

uint32 Randomizer::Next | ( | uint32 | limit | ) |

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

Parameters

  limit | Limit of the range to be generated from.

Returns
  Random number in [0,limit)

Definition at line 46 of file random_func.cpp.

References Next().

## ◆ SetSeed()

void Randomizer::SetSeed | ( | uint32 | seed | ) |

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

Parameters

  seed | the new state

Definition at line 55 of file random_func.cpp.

References state.

Referenced by SetRandomSeed().

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

- src/core/random_func.hpp
- src/core/random_func.cpp