23 std::uniform_real_distribution<Float> dist;
27 mt = std::mt19937_64(seed);
46 const int im1 = 2147483563;
47 const int im2 = 2147483399;
48 const Float am = 1._f / im1;
49 const int imm1 = im1 - 1;
50 const int ia1 = 40014;
51 const int ia2 = 40692;
52 const int iq1 = 53668;
53 const int iq2 = 52774;
54 const int ir1 = 12211;
56 const Float eps = 1.2e-7_f;
57 const Float rnmx = 1._f - eps;
59 static constexpr
int ntab = 32;
62 int idum2 = 123456789;
76 static const int dimension = 6;
96 template <
typename TRng>
102 template <
typename... TArgs>
104 : rng(
std::forward<TArgs>(args)...) {}
111 template <
typename TRng,
typename... TArgs>
113 return makeAuto<RngWrapper<TRng>>(std::forward<TArgs>(args)...);
119 template <
typename TRng>
127 }
while (u1 <= epsilon);
131 return z1 * sigma + mu;
137 template <
typename TRng>
144 }
while (u <= epsilon);
145 return -log(rng()) / lambda;
151 template <
typename TRng>
158 const Float u = rng();
165 template <
typename TRng>
167 const Float phi = rng() * 2._f *
PI;
168 const Float z = rng() * 2._f - 1._f;
183 template <
typename TRng,
typename TFunc>
187 const Float y = rng() * upperBound;
188 const Float pdf = func(x);
189 SPH_ASSERT(pdf >= 0._f && pdf < upperBound, pdf);
202 template <
typename TRng,
typename TFunc>
206 const Float y = rng() * upperBound;
207 const Float pdf = func(r);
208 SPH_ASSERT(pdf >= 0._f && pdf < upperBound, pdf);
INLINE bool isReal(const AntisymmetricTensor &t)
Generic dynamically allocated resizable storage.
#define SPH_ASSERT(x,...)
Simplified implementation of std::unique_ptr, using only default deleter.
Object representing a three-dimensional axis-aligned box.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE T sqrt(const T f)
Return a squared root of a value.
constexpr Float PI
Mathematical constants.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
INLINE Vector sampleUnitSphere(TRng &rng)
Generates a random position on a unit sphere.
AutoPtr< RngWrapper< TRng > > makeRng(TArgs &&... args)
INLINE Size samplePoissonDistribution(TRng &rng, const Float lambda)
Generates a random integer from Poisson distribution.
INLINE Float sampleExponentialDistribution(TRng &rng, const Float lambda)
Generates a random number from exponential distribution.
INLINE Float sampleNormalDistribution(TRng &rng, const Float mu, const Float sigma)
Generates a random number from normal distribution, using Box-Muller algorithm.
INLINE Float sampleDistribution(TRng &rng, const Interval &range, const Float upperBound, const TFunc &func)
Generates a random number from a generic distribution, using rejection sampling.
BasicVector< Float > Vector
Wrapper of pointer that deletes the resource from destructor.
Random number generator used in code SPH5 of Benz & Asphaug (1994).
BenzAsphaugRng(const int seed)
Float operator()(const int s=0)
Helper object defining three-dimensional interval (box).
INLINE const Vector & lower() const
Returns lower bounds of the box.
INLINE Vector size() const
Returns box dimensions.
Quasi-random number generator.
Float operator()(const int s)
Polymorphic holder allowing to store any RNG (type erasure).
virtual Float operator()(const int s=0)=0
Generates a random number.
Object representing a 1D interval of real numbers.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float size() const
Returns the size of the interval.
RngWrapper(TArgs &&... args)
virtual Float operator()(const int s) override
Generates a random number.
Overload of std::swap for Sph::Array.
Object with deleted copy constructor and copy operator.
Base class for all polymorphic objects.