Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::Random Namespace Reference

Functions

std::mt19937 & GetRNG ()
void Seed (uint32_t seed)
uint32_t UInt1 (uint32_t max)
bool Bool1 (float trueChance)
unsigned char Char ()
std::string String (size_t length)
std::string HexString (size_t length)
std::string UUID ()
float Float1 ()
float RangeF1 (float min, float max)
float RangeF1_Inclusive (float min, float max)
glm::vec2 Float2 ()
glm::vec2 RangeF2 (float min, float max)
glm::vec2 RangeF2 (float min1, float max1, float min2, float max2)
glm::vec2 RangeF2 (const glm::vec2 &minRange, const glm::vec2 &maxRange)
glm::vec3 Float3 ()
glm::vec3 RangeF3 (float min, float max)
glm::vec3 RangeF3 (float min1, float max1, float min2, float max2, float min3, float max3)
glm::vec3 RangeF3 (const glm::vec2 &range1, const glm::vec2 &range2, const glm::vec2 &range3)
glm::vec4 Float4 ()
glm::vec4 RangeF4 (float min, float max)

Function Documentation

◆ Bool1()

bool Vesper::Random::Bool1 ( float trueChance)
inline
31 {
33 std::uniform_real_distribution<float> dist(0.0f, 1.0f);
34 return dist(GetRNG()) < trueChance;
35 }
#define VZ_PROFILE_FUNCTION()
Definition Instrumentor.h:240
std::mt19937 & GetRNG()
Definition Random.h:16

◆ Char()

unsigned char Vesper::Random::Char ( )
inline
37 {
39 std::uniform_int_distribution<int> dist(0, 255);
40 return static_cast<unsigned char>(dist(GetRNG()));
41 }

◆ Float1()

float Vesper::Random::Float1 ( )
inline
76 {
78 static thread_local std::uniform_real_distribution<float> dist(0.0f, 1.0f);
79 return dist(GetRNG());
80 }

Referenced by Vesper::ParticleSystem::Emit().

◆ Float2()

glm::vec2 Vesper::Random::Float2 ( )
inline
100 {
101 return glm::vec2{ Float1(), Float1() };
102 }
float Float1()
Definition Random.h:76

◆ Float3()

glm::vec3 Vesper::Random::Float3 ( )
inline
121 {
122 return glm::vec3{ Float1(), Float1(), Float1() };
123 }

◆ Float4()

glm::vec4 Vesper::Random::Float4 ( )
inline
141 {
142 return glm::vec4{ Float1(), Float1(), Float1(), Float1() };
143 }

◆ GetRNG()

std::mt19937 & Vesper::Random::GetRNG ( )
inline
16 {
17 static thread_local std::mt19937 rng{ std::random_device{}() };
18 return rng;
19 }

Referenced by Seed().

◆ HexString()

std::string Vesper::Random::HexString ( size_t length)
inline
57 {
59 const char charset[] =
60 "0123456789"
61 "ABCDEF";
62 const size_t max_index = (sizeof(charset) - 1);
63 std::string str(length, 0);
64 for (size_t i = 0; i < length; ++i) {
65 str[i] = charset[UInt1(static_cast<uint32_t>(max_index))];
66 }
67 return str;
68 }
uint32_t UInt1(uint32_t max)
Definition Random.h:25

References UInt1().

◆ RangeF1()

float Vesper::Random::RangeF1 ( float min,
float max )
inline
84 {
86 if (min > max) std::swap(min, max);
87 std::uniform_real_distribution<float> dist(min, max);
88 return dist(GetRNG());
89 }

◆ RangeF1_Inclusive()

float Vesper::Random::RangeF1_Inclusive ( float min,
float max )
inline
92 {
93 if (min > max) std::swap(min, max);
94 float upper = std::nextafter(max, std::numeric_limits<float>::infinity());
95 std::uniform_real_distribution<float> dist(min, upper);
96 return dist(GetRNG());
97 }

◆ RangeF2() [1/3]

glm::vec2 Vesper::Random::RangeF2 ( const glm::vec2 & minRange,
const glm::vec2 & maxRange )
inline
115 {
116 return glm::vec2{ RangeF1(minRange.x, maxRange.x), RangeF1(minRange.y, maxRange.y) };
117 }
float RangeF1(float min, float max)
Definition Random.h:84

◆ RangeF2() [2/3]

glm::vec2 Vesper::Random::RangeF2 ( float min,
float max )
inline
105 {
106 return glm::vec2{ RangeF1(min, max), RangeF1(min, max) };
107 }

◆ RangeF2() [3/3]

glm::vec2 Vesper::Random::RangeF2 ( float min1,
float max1,
float min2,
float max2 )
inline
110 {
111 return glm::vec2{ RangeF1(min1, max1), RangeF1(min2, max2) };
112 }

◆ RangeF3() [1/3]

glm::vec3 Vesper::Random::RangeF3 ( const glm::vec2 & range1,
const glm::vec2 & range2,
const glm::vec2 & range3 )
inline
136 {
137 return glm::vec3{ RangeF1(range1.x, range1.y), RangeF1(range2.x, range2.y), RangeF1(range3.x, range3.y) };
138 }

◆ RangeF3() [2/3]

glm::vec3 Vesper::Random::RangeF3 ( float min,
float max )
inline
126 {
127 return glm::vec3{ RangeF1(min, max), RangeF1(min, max), RangeF1(min, max) };
128 }

◆ RangeF3() [3/3]

glm::vec3 Vesper::Random::RangeF3 ( float min1,
float max1,
float min2,
float max2,
float min3,
float max3 )
inline
131 {
132 return glm::vec3{ RangeF1(min1, max1), RangeF1(min2, max2), RangeF1(min3, max3) };
133 }

◆ RangeF4()

glm::vec4 Vesper::Random::RangeF4 ( float min,
float max )
inline
146 {
147 return glm::vec4{ RangeF1(min, max), RangeF1(min, max), RangeF1(min, max), RangeF1(min, max) };
148 }

◆ Seed()

void Vesper::Random::Seed ( uint32_t seed)
inline
21 {
22 GetRNG().seed(seed);
23 }

References GetRNG().

◆ String()

std::string Vesper::Random::String ( size_t length)
inline
43 {
45 const char charset[] =
46 "0123456789"
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
48 "abcdefghijklmnopqrstuvwxyz";
49 const size_t max_index = (sizeof(charset) - 1);
50 std::string str(length, 0);
51 for (size_t i = 0; i < length; ++i) {
52 str[i] = charset[UInt1(static_cast<uint32_t>(max_index))];
53 }
54 return str;
55 }

References UInt1().

◆ UInt1()

uint32_t Vesper::Random::UInt1 ( uint32_t max)
inline
25 {
27 std::uniform_int_distribution<uint32_t> dist(0, max - 1);
28 return dist(GetRNG());
29 }

Referenced by HexString(), and String().

◆ UUID()

std::string Vesper::Random::UUID ( )
inline
70 {
72 return HexString(8) + "-" + HexString(4) + "-" + HexString(4) + "-" + HexString(4) + "-" + HexString(12);
73 }
std::string HexString(size_t length)
Definition Random.h:57