Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Random.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7namespace ph::math
8{
9
10template<std::size_t N, typename T>
11inline std::array<T, N> Random::sampleND()
12{
13 static_assert(N != 0);
14
15 std::array<T, N> values;
16 for(std::size_t n = 0; n < N; ++n)
17 {
18 values[n] = static_cast<T>(sample());
19 }
20 return values;
21}
22
23inline std::size_t Random::index(const std::size_t lowerBound, const std::size_t upperBound)
24{
25 PH_ASSERT_GT(upperBound, lowerBound);
26
27 const std::size_t numIntervals = upperBound - lowerBound;
28 std::size_t index = static_cast<std::size_t>(lowerBound + sample() * numIntervals);
29
30 return index < lowerBound ? lowerBound : (index >= upperBound ? upperBound - 1 : index);
31}
32
33}// end namespace ph::math
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