CoriEngine
Loading...
Searching...
No Matches
Random.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace Cori {
4 namespace Utility {
8 class RandomUint32 {
9 public:
14 static uint32_t Gen() {
15 if (!Get().m_DistFullRange) {
16 Get().m_DistFullRange.emplace();
17 }
18 return (*Get().m_DistFullRange)(Get().gen);
19 }
20
27 static uint32_t Gen(const uint32_t min, const uint32_t max) {
28 std::uniform_int_distribution dist(min, max);
29 return dist(Get().gen);
30 }
31
32 private:
33 RandomUint32() : gen(std::random_device{}()) {}
34
35 static RandomUint32& Get() {
36 static RandomUint32 instance;
37 return instance;
38 }
39
40 std::mt19937 gen;
41 std::optional<std::uniform_int_distribution<uint32_t>> m_DistFullRange;
42 };
43 }
44}
Random uint32_t generator.
Definition Random.hpp:8
static uint32_t Gen(const uint32_t min, const uint32_t max)
Generates a random uint32_t with a range constraint.
Definition Random.hpp:27
static uint32_t Gen()
Generates a random uint32_t without a range constraints.
Definition Random.hpp:14
A namespace for utilities of different kinds.
Definition AABB.hpp:7
Global engine namespace.