Skip to main content

Random.ixx File

Utility class for pseudo-random number generation. More...

Included Headers

#include <cstdint> #include <random>

Namespaces Index

namespacehelios
namespaceengine
namespaceutil

Classes Index

classRandom

Utility class for generating pseudo-random numbers. More...

Description

Utility class for pseudo-random number generation.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cstdint>
8#include <random>
9
10export module helios.engine.util.Random;
11
12
13export namespace helios::engine::util {
14
27 class Random {
28
29 private:
30
34 std::mt19937 gen_;
35
41 std::uniform_real_distribution<float> uniformDist_;
42
49 uint32_t initialSeed_;
50
51 public:
52
58 explicit Random(const uint32_t seed) : gen_(seed), initialSeed_(seed) {};
59
66 void reset() {
67 gen_.seed(initialSeed_);
68
69 uniformDist_.reset();
70 }
71
85 [[nodiscard]] float randomFloat(float a, float b) noexcept {
86
87 if (b < a) {
88 auto tmp = a; a = b; b = tmp;
89 }
90
91 if (a == b) {
92 return a;
93 }
94
95 return uniformDist_(
96 gen_,
97 std::uniform_real_distribution<float>::param_type{a, b}
98 );
99 }
100
101 };
102
103
104}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.