File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
loader/include/Geode/utils Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,19 @@ namespace geode::utils::random {
5252
5353 // / Generates a random value of type T, in the range [min, max),
5454 // / meaning the max value can never be returned
55- template <typename T, typename Y, typename Out = std::common_type_t <T, Y>>
56- Out generate (T min, Y max) {
55+ template <typename R = void , typename T, typename Y>
56+ auto generate (T min_, Y max_) {
57+ using Out = std::conditional_t <std::is_void_v<R>, std::common_type_t <T, Y>, R>;
58+
59+ Out min = static_cast <Out>(min_);
60+ Out max = static_cast <Out>(max_);
61+
5762 if (max <= min) return min;
5863
5964 if constexpr (std::is_integral_v<Out>) {
6065 Out range = max - min;
6166 uint64_t val = nextU64 ();
62- return static_cast <Out>(min) + (val % range);
67+ return static_cast <Out>(static_cast <Out>( min) + (val % range) );
6368 } else if constexpr (std::is_floating_point_v<Out>) {
6469 double range = static_cast <double >(max) - static_cast <double >(min);
6570 double val = generate<double >();
You can’t perform that action at this time.
0 commit comments