30__pragma(warning(push))
31__pragma(warning(disable:4244))
52namespace vctr::random::detail
55consteval auto getTimeFromString (
const char* str,
int offset)
57 return static_cast<uint32_t
> (str[offset] -
'0') * 10 +
static_cast<uint32_t
> (str[offset + 1] -
'0');
61consteval auto getSeedFromCurrentTime()
64 return getTimeFromString (t, 0) * 60 * 60 + getTimeFromString (t, 3) * 60 + getTimeFromString (t, 6);
72consteval uint32_t uniformDistribution (uint32_t& previous)
74 constexpr uint32_t lce_a = 48271;
75 constexpr uint32_t lce_c = 0;
76 constexpr uint32_t lce_m = std::numeric_limits<int32_t>::max();
77 previous = ((lce_a * previous + lce_c) % lce_m);
83consteval T uniformDistribution (T
min, T
max, uint32_t& seed)
85 auto span = double (
max -
min);
86 constexpr auto scale = double (std::numeric_limits<int32_t>::max());
87 return T (
double (uniformDistribution (seed)) / scale * (span)) +
min;
94template <
size_t size,
typename T>
95consteval auto makeArrayWithUniformDistribution (T
min, T
max, uint32_t seed)
97 std::array<T, size> dst {};
99 el = uniformDistribution (
min,
max, seed);
110template <
size_t size, std::
floating_po
int T>
111consteval auto makeArrayWithNormalDistribution (T
mean, T sigma, uint32_t seed)
113 std::array<T, size> dst {};
115 for (
size_t i = 0; i < size - 1; i += 2)
124 u1 = uniformDistribution (T (0), T (1), seed);
125 u2 = uniformDistribution (T (0), T (1), seed);
126 }
while (u1 <= std::numeric_limits<T>::epsilon());
135 auto mag = sigma * gcem::sqrt (T (-2) * gcem::log (u1));
136 auto twoPiU2 = std::numbers::pi_v<T> * 2 * u2;
137 dst[i] = mag * gcem::cos (twoPiU2) +
mean;
141 dst[i + 1] = mag * gcem::sin (twoPiU2) +
mean;
148namespace vctr::random
156template <
size_t size,
typename T>
157consteval auto makeArrayWithUniformDistribution (T
min, T
max, uint32_t seedOffset = 0)
159 return detail::makeArrayWithUniformDistribution<size, T> (
min,
max, detail::getSeedFromCurrentTime() + seedOffset);
165template <
size_t size, std::
floating_po
int T>
166consteval auto makeArrayWithNormalDistribution (T
mean, T sigma)
168 return detail::makeArrayWithNormalDistribution<size, T> (
mean, sigma, detail::getSeedFromCurrentTime());
constexpr ExpressionChainBuilder< expressions::Mean > mean
Computes the mean value of the source values.
Definition: Mean.h:242
constexpr ExpressionChainBuilder< expressions::Max > max
Computes the maximum value of the source values.
Definition: Max.h:194
constexpr ExpressionChainBuilder< expressions::Min > min
Computes the minimum value of the source values.
Definition: Min.h:194