CARLA
Loading...
Searching...
No Matches
RandomEngine.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
8#include "Carla.h"
9
13
14#include <limits>
15
17{
18 // Tuned to be fast as this function might get called relatively often.
19 static thread_local std::mt19937_64 Engine((std::random_device())());
20 std::uniform_int_distribution<uint64> Distribution(
21 std::numeric_limits<uint64>::lowest(),
22 std::numeric_limits<uint64>::max());
23 return Distribution(Engine);
24}
25
27{
28 std::random_device RandomDevice;
29 std::uniform_int_distribution<int32> Distribution(
30 std::numeric_limits<int32>::lowest(),
31 std::numeric_limits<int32>::max());
32 return Distribution(RandomDevice);
33}
34
36{
38 std::numeric_limits<int32>::lowest(),
39 std::numeric_limits<int32>::max());
40}
41
46
uint32 GetState() const
The engine's state, to continue its exact sequence elsewhere (a Multi-GPU secondary's mirror of a sen...
std::minstd_rand Engine
int32 GetUniformIntInRange(int32 Minimum, int32 Maximum)
static uint64 GenerateRandomId()
Generate a non-deterministic random id.
void SetState(uint32 State)
Continue from State, as GetState returned it; an impossible value is ignored.
static int32 GenerateRandomSeed()
Generate a non-deterministic random seed.
int32 GenerateSeed()
Generate a seed derived from previous seed.
uint32_t GetEngineState(const std::minstd_rand &engine)
The state of a minstd_rand: the value its next draw is computed from.
Definition sensorSync.h:254
bool SetEngineState(std::minstd_rand &engine, uint32_t state)
Makes engine continue from state, as GetEngineState returned it.
Definition sensorSync.h:264