5#include <Common/assertion.h>
10template<std::
size_t N,
typename T>
13 static_assert(N != 0);
15 std::array<T, N> values;
16 for(std::size_t n = 0; n < N; ++n)
18 values[n] =
static_cast<T
>(
sample());
23inline std::size_t
Random::index(
const std::size_t lowerBound,
const std::size_t upperBound)
25 PH_ASSERT_GT(upperBound, lowerBound);
27 const std::size_t numIntervals = upperBound - lowerBound;
28 std::size_t
index =
static_cast<std::size_t
>(lowerBound +
sample() * numIntervals);
30 return index < lowerBound ? lowerBound : (
index >= upperBound ? upperBound - 1 :
index);
static std::array< T, N > sampleND()
Similar to sample(), except the sample is N-dimensional.
Definition Random.ipp:11
static std::size_t index(std::size_t lowerBound, std::size_t upperBound)
Get a uniform random integer value in [lowerBound, upperBound).
Definition Random.ipp:23
static real sample()
Get a uniform random value in [0, 1].
Definition Random.cpp:44
Math functions and utilities.
Definition TransformInfo.h:10