FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_random.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_RANDOM_HPP_INCLUDED
18#define _FGE_C_RANDOM_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_vector.hpp"
22#include "FastEngine/graphic/C_color.hpp"
23
24#include <chrono>
25#include <limits>
26#include <mutex>
27#include <random>
28#include <string>
29
30namespace fge
31{
32
41template<typename TEngine>
42class Random
43{
44public:
45 Random();
51 explicit Random(uint64_t seed);
52
58 void setSeed(uint64_t seed);
59
68 template<typename T>
69 T range(T min, T max);
70
76 [[nodiscard]] TEngine const& getEngine() const;
82 [[nodiscard]] TEngine& getEngine();
83
94 template<typename T>
95 fge::Vector2<T> rangeVec2(T min_x, T max_x, T min_y, T max_y);
96
109 template<typename T>
110 fge::Vector3<T> rangeVec3(T min_x, T max_x, T min_y, T max_y, T min_z, T max_z);
111
119 fge::Color rangeColor(uint32_t min, uint32_t max);
133 fge::Color rangeColor(uint8_t min_r,
134 uint8_t max_r,
135 uint8_t min_g,
136 uint8_t max_g,
137 uint8_t min_b,
138 uint8_t max_b,
139 uint8_t min_a,
140 uint8_t max_a);
141
148 template<typename T>
149 T rand();
150
157 template<typename T>
158 fge::Vector2<T> randVec2();
159
166 template<typename T>
167 fge::Vector3<T> randVec3();
168
175
186 std::string randStr(std::size_t length,
187 std::string const& bucket = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy0123456789");
188
189private:
190 TEngine g_engine;
191 std::mutex g_mutex;
192};
193
202
203} // namespace fge
204
205#include <FastEngine/C_random.inl>
206
207#endif // _FGE_C_RANDOM_HPP_INCLUDED
Definition C_color.hpp:35
A class to generate random numbers.
Definition C_random.hpp:43
fge::Vector2< T > rangeVec2(T min_x, T max_x, T min_y, T max_y)
Generate a random vector2 within a range.
Definition C_random.inl:87
fge::Vector2< T > randVec2()
Generate a random vector2.
Definition C_random.inl:120
fge::Vector3< T > randVec3()
Generate a random vector3.
Definition C_random.inl:127
fge::Color rangeColor(uint32_t min, uint32_t max)
Generate a random color.
Definition C_random.inl:100
fge::Color randColor()
Generate a random color.
Definition C_random.inl:133
TEngine const & getEngine() const
Get the random engine.
Definition C_random.inl:37
void setSeed(uint64_t seed)
Set the 64-bit seed of the random number generator.
Definition C_random.inl:30
fge::Vector3< T > rangeVec3(T min_x, T max_x, T min_y, T max_y, T min_z, T max_z)
Generate a random vector3 within a range.
Definition C_random.inl:94
T range(T min, T max)
Generate a random number within a range.
Definition C_random.inl:49
T rand()
Generate a random value.
Definition C_random.inl:68
std::string randStr(std::size_t length, std::string const &bucket="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy0123456789")
Generate a random character sequence.
Definition C_random.inl:139
FGE_API fge::Random< std::mt19937_64 > _random
Default random number generator instance.