Generate seedable random numbers of various types and in multiple intervals. Handles per-thread random number generators.
More...
#include <Random.hpp>
|
struct | LocalMT19937 |
| A MT19937 generator seeded using the shared generator. Used to provide per-thread MT19937 generators in a thread-safe way. More...
|
|
|
static unsigned int | _seed |
| The current main seed.
|
|
static std::mt19937 | _shared |
| Shared randomness generator, used for seeding per-thread generators. More...
|
|
static std::mutex | _lock |
| The lock for the shared generator.
|
|
static thread_local LocalMT19937 | _thread |
| Per-thread randomness generator, seeded using the shared generator.
|
|
Generate seedable random numbers of various types and in multiple intervals. Handles per-thread random number generators.
◆ Color()
glm::vec3 Random::Color |
( |
| ) |
|
|
static |
Generate a random color in RGB color space. Internally a HSV color with reasonable saturation and luminance is generated and converted to RGB.
- Returns
- an RGB triplet.
◆ Float() [1/2]
Generate a float in [0.0, 1.0)
- Returns
- a float in [0.0, 1.0)
◆ Float() [2/2]
float Random::Float |
( |
float |
min, |
|
|
float |
max |
|
) |
| |
|
static |
Generate a float in a given interval.
- Parameters
-
min | the included lower bound |
max | the excluded higher bound |
- Returns
- a float in [min, max)
◆ getSeed()
unsigned int Random::getSeed |
( |
| ) |
|
|
static |
Query the current global seed.
- Returns
- the current global seed
◆ Int()
int Random::Int |
( |
int |
min, |
|
|
int |
max |
|
) |
| |
|
static |
Generate an integer in a given interval.
- Parameters
-
min | the included lower bound |
max | the included higher bound |
- Returns
- an integer in [min, max]
◆ sampleCosineHemisphere()
glm::vec3 Random::sampleCosineHemisphere |
( |
| ) |
|
|
static |
Sample point from the hemisphere, following a cosine lobe
- Returns
- a 3D point on the unit z-positive hemisphere
◆ sampleDisk()
glm::vec2 Random::sampleDisk |
( |
| ) |
|
|
static |
Sample point uniformly on a disk.
- Returns
- a 2D point on the unit disk
◆ sampleSphere()
glm::vec3 Random::sampleSphere |
( |
| ) |
|
|
static |
Sample point uniformly on a sphere.
- Returns
- a 3D point on the unit sphere
◆ seed() [1/2]
Seed the shared generator using a random number.
- Note
- The seed is obtained through a std::random_device.
- Warning
- Threads created before the call won't be seeded (except for the calling thread).
- Note
- It is recommended to seed the generator on the main thread at the beginning of the application execution.
◆ seed() [2/2]
void Random::seed |
( |
unsigned int |
seedValue | ) |
|
|
static |
Seed the shared generator using a given number.
- Parameters
-
- Warning
- Threads created before the call won't be seeded (except for the calling thread).
- Note
- It is recommended to seed the generator on the main thread at the beginning of the application execution.
◆ shuffle()
template<typename T >
void Random::shuffle |
( |
std::vector< T > & |
items | ) |
|
|
static |
Shuffle elements of a vector randomly, in-place.
- Parameters
-
items | the items to shuffle |
◆ _shared
std::mt19937 Random::_shared |
|
staticprivate |
Shared randomness generator, used for seeding per-thread generators.
- Warning
- Not thread safe.
The documentation for this class was generated from the following files:
- src/engine/generation/Random.hpp
- src/engine/generation/Random.cpp