-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rand.hpp
executable file
·37 lines (30 loc) · 1.03 KB
/
Rand.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include <random>
#include <concepts>
#include "Point3D.hpp"
std::random_device rndm_dev; // these 2 lines are outside the
std::mt19937 rndm_mt(rndm_dev()); // fuction to increase performance
template <typename T> requires std::floating_point<T> || std::integral<T>
Point3D<T> rand_coord(const Point3D<T>& low_lim, const Point3D<T>& up_lim, const Color& col={})
{
if constexpr (std::is_floating_point_v<T>)
{
std::uniform_real_distribution<T> xgen(low_lim.x, up_lim.x);
std::uniform_real_distribution<T> ygen(low_lim.y, up_lim.y);
std::uniform_real_distribution<T> zgen(low_lim.z, up_lim.z);
T x = xgen(rndm_mt);
T y = ygen(rndm_mt);
T z = zgen(rndm_mt);
return {x,y,z, col};
}
else if constexpr (std::is_integral_v<T>)
{
std::uniform_int_distribution<T> xgen(low_lim.x, up_lim.x);
std::uniform_int_distribution<T> ygen(low_lim.y, up_lim.y);
std::uniform_int_distribution<T> zgen(low_lim.z, up_lim.z);
T x = xgen(rndm_mt);
T y = ygen(rndm_mt);
T z = zgen(rndm_mt);
return {x,y,z, col};
}
}