9#include "pcg_cpp/pcg_extras.hpp"
10#include "pcg_cpp/pcg_random.hpp"
12#include "ll/api/base/StdInt.h"
14namespace ll::inline utils::random_utils {
16template <std::
integral T>
17inline T rand(T upBound = 0) {
18 static pcg64 random{pcg_extras::seed_seq_from<std::random_device>{}};
20 constexpr auto digits = std::numeric_limits<T>::digits;
22 return static_cast<T
>(random(upBound));
23 }
else if constexpr (digits != 64) {
24 static auto u = (uintmax_t)std::pow<ldouble>(2ull, digits);
25 return static_cast<T
>(random(u));
27 return static_cast<T
>(random());
30template <std::
floating_po
int T>
36 auto r = rand<uintmax_t>();
37 x.f = std::numeric_limits<T>::max();
39 x.f = std::numeric_limits<T>::infinity();
41 x.f =
static_cast<T
>(1);
45 return x.f -
static_cast<T
>(1);
47template <std::
floating_po
int T>
49 return rand<T>() * max;
52inline T rand(T min, T max) {
53 return min + rand<T>(max - min);
56inline T openIntervalRand(T min = 0, T max = 1) {
57 return rand<T>(std::nexttoward(min, std::numeric_limits<long double>::max()), max);
60inline T closeIntervalRand(T min = 0, T max = 1) {
61 return rand<T>(min, std::nexttoward(max, std::numeric_limits<long double>::max()));
64inline T rightCloseIntervalRand(T min = 0, T max = 1) {
66 std::nexttoward(min, std::numeric_limits<long double>::max()),
67 std::nexttoward(max, std::numeric_limits<long double>::max())
71inline T leftCloseIntervalRand(T min = 0, T max = 1) {
72 return rand<T>(min, max);