-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRandom.mpp
More file actions
18 lines (16 loc) · 572 Bytes
/
Random.mpp
File metadata and controls
18 lines (16 loc) · 572 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export module CppUtils.Math.Random;
import std;
export namespace CppUtils::Math
{
template<std::integral Integer>
inline auto getRandomNumberInInterval(Integer min, Integer max) -> Integer
{
thread_local auto engine = [] {
static auto randomDevice = std::random_device{};
return std::mt19937{static_cast<std::mt19937::result_type>(randomDevice() ^ std::hash<std::thread::id>{}(std::this_thread::get_id()))};
}();
auto distribution = std::uniform_int_distribution<Integer>{min, max};
auto randomNumber = distribution(engine);
return randomNumber;
}
}