GigaPasjans
Loading...
Searching...
No Matches
Random.h
1// Wykonane przez Piotra ChudziƄskiego w dniu 15.04.2025
2#pragma once
3
4#include "Common.h"
5// TODO: add that to cmake
6#define USE_LINEAR_CONGRUENTIAL
7// #define USE_MERSENNE_TWISTER
8#include <random>
9#include <stack>
10
15class Random
16{
17private:
22 inline static bool m_Initialized;
23
24 inline static std::stack<uint32> m_SeedStack;
25
30 inline static std::random_device m_RandomDevice;
31#ifdef USE_LINEAR_CONGRUENTIAL
32 inline static std::minstd_rand m_Generator;
33#endif
34#ifdef USE_MERSENNE_TWISTER
35 inline static std::mt19937_64 m_Generator;
36#endif
37
42 FORCE_INLINE static void initialize();
43
44public:
45 static void PushSeed(uint32 seed);
46 static void PopSeed(int32 count = 1);
47
52 static int32 RandInt(const int32 min, const int32 max);
53
58 static String RandString(const int32 length);
59
64 template<typename T>
65 FORCE_INLINE static void ShuffleVector(std::vector<T> &vector)
66 {
67 std::ranges::shuffle(vector, m_Generator);
68 }
69};
A utility which contains essential function for pseudorandom generating.
Definition Random.h:16
static FORCE_INLINE void ShuffleVector(std::vector< T > &vector)
Randomly shuffles a list.
Definition Random.h:65
static String RandString(const int32 length)
Returns random string with given length using digits and alphabet letters.
Definition Random.cpp:32
static int32 RandInt(const int32 min, const int32 max)
Returns random value between min and max.
Definition Random.cpp:23
Represents a mutable sequence of characters, providing various member functions for string manipulati...
Definition String.h:16