Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::Random Namespace Reference

Functions

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

Function Documentation

◆ Bool1()

bool Muto::Random::Bool1 ( float  trueChance)
inline
34 {
36 std::uniform_real_distribution<float> dist(0.0f, 1.0f);
37 return dist(GetRNG()) < trueChance;
38 }
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
std::mt19937 & GetRNG()
Definition Random.h:19

References GetRNG().

◆ Char()

unsigned char Muto::Random::Char ( )
inline
40 {
42 std::uniform_int_distribution<int> dist(0, 255);
43 return static_cast<unsigned char>(dist(GetRNG()));
44 }

References GetRNG().

◆ Float1()

float Muto::Random::Float1 ( )
inline
79 {
81 static thread_local std::uniform_real_distribution<float> dist(0.0f, 1.0f);
82 return dist(GetRNG());
83 }

References GetRNG().

Referenced by Muto::ParticleSystem::Emit(), and Muto::ParticleSystem::ResetParticle().

◆ Float2()

glm::vec2 Muto::Random::Float2 ( )
inline
103 {
104 return glm::vec2{ Float1(), Float1() };
105 }
float Float1()
Definition Random.h:79

◆ Float3()

glm::vec3 Muto::Random::Float3 ( )
inline
124 {
125 return glm::vec3{ Float1(), Float1(), Float1() };
126 }

◆ Float4()

glm::vec4 Muto::Random::Float4 ( )
inline
144 {
145 return glm::vec4{ Float1(), Float1(), Float1(), Float1() };
146 }

◆ GetRNG()

std::mt19937 & Muto::Random::GetRNG ( )
inline
19 {
20 static thread_local std::mt19937 rng{ std::random_device{}() };
21 return rng;
22 }

Referenced by Bool1(), Char(), Float1(), RangeF1(), RangeF1_Inclusive(), Seed(), and UInt1().

◆ HexString()

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

References UInt1().

Referenced by UUID().

◆ RangeF1()

float Muto::Random::RangeF1 ( float  min,
float  max 
)
inline
87 {
89 if (min > max) std::swap(min, max);
90 std::uniform_real_distribution<float> dist(min, max);
91 return dist(GetRNG());
92 }

References GetRNG().

◆ RangeF1_Inclusive()

float Muto::Random::RangeF1_Inclusive ( float  min,
float  max 
)
inline
95 {
96 if (min > max) std::swap(min, max);
97 float upper = std::nextafter(max, std::numeric_limits<float>::infinity());
98 std::uniform_real_distribution<float> dist(min, upper);
99 return dist(GetRNG());
100 }

References GetRNG().

◆ RangeF2() [1/3]

glm::vec2 Muto::Random::RangeF2 ( const glm::vec2 &  minRange,
const glm::vec2 &  maxRange 
)
inline
118 {
119 return glm::vec2{ RangeF1(minRange.x, maxRange.x), RangeF1(minRange.y, maxRange.y) };
120 }
float RangeF1(float min, float max)
Definition Random.h:87

◆ RangeF2() [2/3]

glm::vec2 Muto::Random::RangeF2 ( float  min,
float  max 
)
inline
108 {
109 return glm::vec2{ RangeF1(min, max), RangeF1(min, max) };
110 }

◆ RangeF2() [3/3]

glm::vec2 Muto::Random::RangeF2 ( float  min1,
float  max1,
float  min2,
float  max2 
)
inline
113 {
114 return glm::vec2{ RangeF1(min1, max1), RangeF1(min2, max2) };
115 }

◆ RangeF3() [1/3]

glm::vec3 Muto::Random::RangeF3 ( const glm::vec2 &  range1,
const glm::vec2 &  range2,
const glm::vec2 &  range3 
)
inline
139 {
140 return glm::vec3{ RangeF1(range1.x, range1.y), RangeF1(range2.x, range2.y), RangeF1(range3.x, range3.y) };
141 }

◆ RangeF3() [2/3]

glm::vec3 Muto::Random::RangeF3 ( float  min,
float  max 
)
inline
129 {
130 return glm::vec3{ RangeF1(min, max), RangeF1(min, max), RangeF1(min, max) };
131 }

◆ RangeF3() [3/3]

glm::vec3 Muto::Random::RangeF3 ( float  min1,
float  max1,
float  min2,
float  max2,
float  min3,
float  max3 
)
inline
134 {
135 return glm::vec3{ RangeF1(min1, max1), RangeF1(min2, max2), RangeF1(min3, max3) };
136 }

◆ RangeF4()

glm::vec4 Muto::Random::RangeF4 ( float  min,
float  max 
)
inline
149 {
150 return glm::vec4{ RangeF1(min, max), RangeF1(min, max), RangeF1(min, max), RangeF1(min, max) };
151 }

◆ Seed()

void Muto::Random::Seed ( uint32_t  seed)
inline
24 {
25 GetRNG().seed(seed);
26 }

References GetRNG().

◆ String()

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

References UInt1().

◆ UInt1()

uint32_t Muto::Random::UInt1 ( uint32_t  max)
inline
28 {
30 std::uniform_int_distribution<uint32_t> dist(0, max - 1);
31 return dist(GetRNG());
32 }

References GetRNG().

Referenced by HexString(), and String().

◆ UUID()

std::string Muto::Random::UUID ( )
inline
73 {
75 return HexString(8) + "-" + HexString(4) + "-" + HexString(4) + "-" + HexString(4) + "-" + HexString(12);
76 }
std::string HexString(size_t length)
Definition Random.h:60

References HexString().

Referenced by Muto::UUID::UUID().