23#ifndef VCL_ALGORITHMS_CORE_RANDOM_H
24#define VCL_ALGORITHMS_CORE_RANDOM_H
26#include <vclib/space/core.h>
57inline int poissonRatioOfUniformsInteger(
double L, std::mt19937& gen)
60 const double SHAT1 = 2.943035529371538573;
61 const double SHAT2 = 0.8989161620588987408;
68 double pois_a = L + 0.5;
70 double pois_g = std::log(L);
72 double pois_h = std::sqrt(SHAT1 * (L + 0.5)) + SHAT2;
73 double pois_bound = (int) (pois_a + 6.0 * pois_h);
75 std::uniform_real_distribution<double> unif(0, 1);
81 x = pois_a + pois_h * (unif(gen) - 0.5) / u;
82 if (x < 0 || x >= pois_bound)
86 if (lf >= u * (4.0 - u) - 3.0)
88 if (u * (u - lf) > 1.0)
90 if (2.0 * log(u) <= lf)
96inline int poissonRatioOfUniformsInteger(
double L)
98 static std::random_device rd;
99 static std::mt19937 gen(rd());
100 return poissonRatioOfUniformsInteger(L, gen);
124 return detail::poissonRatioOfUniformsInteger(
lambda,
gen);
126 std::uniform_real_distribution<double>
unif(0, 1);
141 static std::random_device rd;
142 static std::mt19937 gen(rd());
143 return detail::poissonRatioOfUniformsInteger(lambda, gen);
156template<Po
int3Concept Po
intType>
159 using ScalarType = PointType::ScalarType;
162 std::uniform_real_distribution<ScalarType>
unif(0, 1);
175template<Po
int3Concept Po
intType>
176PointType randomTriangleBarycentricCoordinate()
178 static std::random_device rd;
179 static std::mt19937 gen(rd());
180 return randomTriangleBarycentricCoordinate<PointType>(gen);
183template<
typename ScalarType>
184std::vector<ScalarType> randomPolygonBarycentricCoordinate(
188 std::vector<ScalarType> barCoord(polySize);
191 std::uniform_real_distribution<ScalarType> unif(0, 100);
193 for (uint i = 0; i < polySize; i++) {
194 barCoord[i] = unif(gen);
197 for (uint i = 0; i < polySize; i++) {
203template<
typename ScalarType>
204std::vector<ScalarType> randomPolygonBarycentricCoordinate(uint polySize)
206 static std::random_device rd;
207 static std::mt19937 gen(rd());
208 return randomPolygonBarycentricCoordinate<ScalarType>(polySize, gen);
A class representing a box in N-dimensional space.
Definition box.h:46
PointType randomTriangleBarycentricCoordinate(std::mt19937 &gen)
Generate the barycentric coords of a random point over a triangle, with a uniform distribution over t...
Definition random.h:157
int poissonRandomNumber(double lambda, std::mt19937 &gen)
algorithm poisson random number (Knuth): init: Let L ← e^−λ, k ← 0 and p ← 1. do: k ← k + 1....
Definition random.h:121
double lnOfFactorial(int n)
Computes and caches the result of the natural logarithm of n!
Definition math.h:112