galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Random.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_MATH_RANDOM_HPP_
9#define GALAXY_MATH_RANDOM_HPP_
10
11#include <random>
12
13#include <Raylib.hpp>
14
16
17namespace galaxy
18{
19 namespace math
20 {
24 template<typename Type>
25 using conditional_distribution = std::conditional_t<
26 std::is_integral<Type>::value,
27 std::uniform_int_distribution<Type>,
28 std::conditional_t<std::is_floating_point<Type>::value, std::uniform_real_distribution<Type>, void>>;
29
40 template<meta::is_arithmetic T>
41 [[nodiscard]]
42 inline T random(const T min, const T max) noexcept
43 {
44 thread_local std::random_device rd;
45 thread_local std::mt19937_64 mt {rd()};
46
47 conditional_distribution<T> dist {min, max};
48 return dist(mt);
49 }
50
59 [[nodiscard]]
60 ray::Vector2 random_vec2(const ray::Vector2& min, const ray::Vector2& max) noexcept;
61
70 [[nodiscard]]
71 ray::Vector3 random_vec3(const ray::Vector3& min, const ray::Vector3& max) noexcept;
72
81 [[nodiscard]]
82 ray::Vector4 random_vec4(const ray::Vector4& min, const ray::Vector4& max) noexcept;
83 } // namespace math
84} // namespace galaxy
85
86#endif
ray::Vector2 random_vec2(const ray::Vector2 &min, const ray::Vector2 &max) noexcept
Generate a random vec2.
Definition Random.cpp:14
ray::Vector3 random_vec3(const ray::Vector3 &min, const ray::Vector3 &max) noexcept
Generate a random vec3.
Definition Random.cpp:19
std::conditional_t< std::is_integral< Type >::value, std::uniform_int_distribution< Type >, std::conditional_t< std::is_floating_point< Type >::value, std::uniform_real_distribution< Type >, void > > conditional_distribution
Source: http://stackoverflow.com/a/32907541.
Definition Random.hpp:25
ray::Vector4 random_vec4(const ray::Vector4 &min, const ray::Vector4 &max) noexcept
Generate a random vec4.
Definition Random.cpp:24
T random(const T min, const T max) noexcept
Generate a random number of type T.
Definition Random.hpp:42
Application.hpp galaxy.