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 {
6 namespace {
7 // Random number generator
8 std::random_device rd;
9 std::mt19937 rng(rd());
10 } // namespace
11
12 int random(int max) {
13 std::uniform_int_distribution<int> dist(0, max);
14 return dist(rng);
15 }
16
17 int between(int min, int max) {
18 std::uniform_int_distribution<int> dist(min, max);
19 return dist(rng);
20 }
21
22 float random(float max) {
23 std::uniform_real_distribution<float> dist(0.0F, max);
24 return dist(rng);
25 }
26
27 float between(float min, float max) {
28 std::uniform_real_distribution<float> dist(min, max);
29 return dist(rng);
30 }
31
32 bool chance() {
33 std::uniform_int_distribution<int> dist(0, 1);
34 return dist(rng) == 1;
35 }
36
37 bool chance(float chance) {
38 std::uniform_real_distribution<float> dist(0.0F, 1.0F);
39 return dist(rng) < chance;
40 }
41} // namespace asw::random
int between(int min, int max)
Generate a random integer between min and max.
Definition random.cpp:17
bool chance()
Generate a random boolean.
Definition random.cpp:32
int random(int max)
Generate a random integer between 0 and max.
Definition random.cpp:12
Random module for the ASW library.