OpenTTD Source: src/core/random_func.cpp File Reference

OpenTTD Source 14.0-beta1

Functions | Variables
random_func.cpp File Reference
`#include "../stdafx.h"`
`#include "random_func.hpp"`
`#include "bitmath_func.hpp"`
`#include "../debug.h"`
`#include "../safeguards.h"`

Go to the source code of this file.

## Functions
void | SetRandomSeed (uint32_t seed)
| (Re)set the state of the random number generators. More...
void | RandomBytesWithFallback (std::span< uint8_t > buf)
| Fill the given buffer with random bytes. More...

## Variables
Randomizer | _random
| Random used in the game state calculations.
Randomizer | _interactive_random
| Random used everywhere else, where it does not (directly) influence the game state.

## Detailed Description

Implementation of the pseudo random generator.

Definition in file random_func.cpp.

## Function Documentation

## ◆ RandomBytesWithFallback()

void RandomBytesWithFallback | ( | std::span< uint8_t > | buf | ) |

Fill the given buffer with random bytes.

This function will attempt to use a cryptographically-strong random generator, but will fall back to a weaker random generator if none is available.

In the end, the buffer will always be filled with some form of random bytes when this function returns.

Parameters

  buf | The buffer to fill with random bytes.

Definition at line 111 of file random_func.cpp.

References Debug.

Referenced by GenerateUid().

## ◆ SetRandomSeed()

void SetRandomSeed | ( | uint32_t | seed | ) |

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

Parameters

  seed | the new state

Definition at line 77 of file random_func.cpp.

References _interactive_random, _random, and Randomizer::SetSeed().

Referenced by StartupOneEngine().