ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
random.cpp
Go to the documentation of this file.
2
3#include <random>
4
5namespace asw::random {
6namespace {
7 // Random number generator
8 std::random_device rd;
9 std::mt19937 rng(rd());
10} // namespace
11
12int random(int max)
13{
14 std::uniform_int_distribution dist(0, max);
15 return dist(rng);
16}
17
18int between(int min, int max)
19{
20 std::uniform_int_distribution dist(min, max);
21 return dist(rng);
22}
23
24float random(float max)
25{
26 std::uniform_real_distribution dist(0.0F, max);
27 return dist(rng);
28}
29
30float between(float min, float max)
31{
32 std::uniform_real_distribution dist(min, max);
33 return dist(rng);
34}
35
36bool chance()
37{
38 std::uniform_int_distribution dist(0, 1);
39 return dist(rng) == 1;
40}
41
42bool chance(float chance)
43{
44 std::uniform_real_distribution dist(0.0F, 1.0F);
45 return dist(rng) < chance;
46}
47} // namespace asw::random
int between(int min, int max)
Generate a random integer between min and max.
Definition random.cpp:18
bool chance()
Generate a random boolean.
Definition random.cpp:36
int random(int max)
Generate a random integer between 0 and max.
Definition random.cpp:12
Random module for the ASW library.