SAT Solver Template
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1/**
2* @author Tim Luchterhand
3* @date 26.11.24
4* @file random.hpp
5* @brief Contains an easy-to-use random number generator
6*/
7
8#ifndef RANDOM_HPP
9#define RANDOM_HPP
10
11#include <random>
12#include <concepts>
13
14namespace sat {
15 /**
16 * @brief Random number generator singleton class
17 */
18 class RNG {
19 std::random_device rd;
20 std::default_random_engine el;
21
22 RNG();
23
24 public:
25
26 RNG(const RNG&) = delete;
27 RNG& operator=(const RNG&) = delete;
28 RNG(RNG&&) = delete;
29 RNG& operator=(RNG&&) = delete;
30 ~RNG() = default;
31
32 /**
33 * Get the instance of the random number generator
34 * @return instance of the random number generator
35 */
36 static RNG &get();
37
38 /**
39 * Sets the random seed
40 * @param seed the desired seed
41 */
42 void setSeed(unsigned seed);
43
44 /**
45 * Generates a random integer value in [min, max]
46 * @tparam T integral type of value
47 * @param min lower bound
48 * @param max upper bound
49 * @return random value
50 */
51 template<std::integral T>
52 T random_int(T min, T max) {
53 std::uniform_int_distribution<T> dist(min, max);
54 return dist(el);
55 }
56
57 /**
58 * Generates a random float value in [min, max)
59 * @tparam T floating point type of value
60 * @param min lower bound
61 * @param max upper bound
62 * @return random value
63 */
64 template<std::floating_point T>
65 T random_float(T min, T max) {
66 std::uniform_real_distribution<T> dist(min, max);
67 return dist(el);
68 }
69 };
70}
71
72#endif //RANDOM_HPP
Random number generator singleton class.
Definition random.hpp:18
T random_float(T min, T max)
Definition random.hpp:65
static RNG & get()
Definition random.cpp:14
void setSeed(unsigned seed)
Definition random.cpp:19
T random_int(T min, T max)
Definition random.hpp:52
Definition basic_structures.cpp:10