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);
123 return detail::poissonRatioOfUniformsInteger(
lambda,
gen);
125 std::uniform_real_distribution<double>
unif(0, 1);
140 static std::random_device rd;
141 static std::mt19937 gen(rd());
142 return detail::poissonRatioOfUniformsInteger(lambda, gen);
155template<Po
int3Concept Po
intType>
158 using ScalarType = PointType::ScalarType;
161 std::uniform_real_distribution<ScalarType>
unif(0, 1);
174template<Po
int3Concept Po
intType>
175PointType randomTriangleBarycentricCoordinate()
177 static std::random_device rd;
178 static std::mt19937 gen(rd());
179 return randomTriangleBarycentricCoordinate<PointType>(gen);
182template<
typename ScalarType>
183std::vector<ScalarType> randomPolygonBarycentricCoordinate(
187 std::vector<ScalarType> barCoord(polySize);
190 std::uniform_real_distribution<ScalarType> unif(0, 100);
192 for (uint i = 0; i < polySize; i++) {
193 barCoord[i] = unif(gen);
196 for (uint i = 0; i < polySize; i++) {
202template<
typename ScalarType>
203std::vector<ScalarType> randomPolygonBarycentricCoordinate(uint polySize)
205 static std::random_device rd;
206 static std::mt19937 gen(rd());
207 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:156
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:120
double lnOfFactorial(int n)
Computes and caches the result of the natural logarithm of n!
Definition math.h:112