styyx-util 1.0
Utility Header for SKSE Plugin development
Loading...
Searching...
No Matches
st-random.h
Go to the documentation of this file.
1#pragma once
2
3namespace StyyxUtil {
4
6 {
11 static int GetRandomInt(const int a_min, const int a_max)
12 {
13 std::uniform_int_distribution<int> distrib(a_min, a_max);
14 return distrib(GetRNG());
15 }
16
21 static float GetRandomFloat(const float a_min, const float a_max)
22 {
23 std::uniform_real_distribution<float> distrib(a_min, a_max);
24 return distrib(GetRNG());
25 }
26
32 static float GetRandomRoundedFloat(const float a_min, const float a_max, const int decimals = 2)
33 {
34 const auto value = GetRandomFloat(a_min, a_max);
35 const double factor = std::pow(10.0, static_cast<double>(decimals));
36 return static_cast<float>(std::round(value * factor) / factor);
37 }
38
43 static double GetRandomDouble(const double a_min, const double a_max) {
44 std::uniform_real_distribution<double> distrib(a_min, a_max);
45 return distrib(GetRNG());
46 }
47
51 static bool IsPercentageChanceFloat(const float a_chancePercent) {
52 return GetRandomFloat(0.0, 100.0) <= a_chancePercent;
53 }
54 private:
55 static std::mt19937& GetRNG()
56 {
57 static std::mt19937 gen(std::random_device{}());
58 return gen;
59 }
60
61 };
62}
Definition st-actor.h:7
Definition st-random.h:6
static int GetRandomInt(const int a_min, const int a_max)
Get random integer between 2 values.
Definition st-random.h:11
static std::mt19937 & GetRNG()
Definition st-random.h:55
static double GetRandomDouble(const double a_min, const double a_max)
Get random double between 2 values.
Definition st-random.h:43
static bool IsPercentageChanceFloat(const float a_chancePercent)
Rolls a random chance check against a given percentage.
Definition st-random.h:51
static float GetRandomRoundedFloat(const float a_min, const float a_max, const int decimals=2)
Get random float rounded to a set amount of decimals.
Definition st-random.h:32
static float GetRandomFloat(const float a_min, const float a_max)
Get random float between 2 values.
Definition st-random.h:21