Flow
Documentation for the Flow C++ Library
Loading...
Searching...
No Matches
flow_random_algorithm.h
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
3#include <concepts>
4#include <random>
5
6namespace flow {
7
12 template <typename T>
13 requires std::integral<T> || std::floating_point<T>
14 T getRandomNumber(T lower, T upper) {
15 static std::random_device device{};
16 static std::mt19937_64 engine(device());
17 if constexpr (std::integral<T>) {
18 return std::uniform_int_distribution<T>(lower, upper)(engine);
19 } else {
20 return std::uniform_real_distribution<T>(lower, upper)(engine);
21 }
22 }
23
27 template <std::random_access_iterator It>
28 void shuffle(It begin, It end) {
29 static std::random_device device{};
30 static std::mt19937_64 engine(device());
31 std::shuffle(begin, end, engine);
32 }
33
34}
void shuffle(It begin, It end)
Randomly shuffle the elements in the range [begin, end).
T getRandomNumber(T lower, T upper)
Produces a random number uniformly distributed on the closed interval [lower, upper].