11 #ifndef __UT_Poisson__
12 #define __UT_Poisson__
29 if (limit_min > limit_max)
32 limit_min = limit_max;
46 const float smallmeanthreshold = 19;
49 const int64 smallmeanmaxi = 50;
50 if (mean < smallmeanthreshold)
53 while (tries < max_tries)
57 const float u = generator.getFloat();
61 if (limit_range && (0 < limit_min || 0 > limit_max))
67 fpreal r0 = u * SYSexp(mean);
70 if (limit_range && (0 < limit_min || 0 > limit_max))
79 if (limit_range && (1 < limit_min || 1 > limit_max))
85 fpreal term = 0.5*mean*mean;
88 while (r0 > f && i < smallmeanmaxi && (!limit_range || i <= limit_max))
95 if (limit_range && (i < limit_min || i > limit_max))
119 f_k *= (mean /
fpreal(curr));
128 f_k *= (
fpreal(curr) / mean);
133 const fpreal s = (a - k)*SYSsqrt(f_k);
138 while (!limit_range || tries < max_tries)
143 const float u = generator.getFloat();
144 const float v = generator.getFloat();
146 x = a + (s * (2 * v - 1) / u);
154 if (limit_range && (result < limit_min || result > limit_max))
165 else if (result > mode)
168 bool stopped =
false;
171 f_x *= (mean /
fpreal(curr));
185 bool stopped =
false;
186 while (curr > result)
188 f_x *= (
fpreal(curr) / mean);
static int64 GetPoisson(fpreal mean, T &generator, bool limit_range=false, int limit_min=-1, int limit_max=-1)
GLboolean GLboolean GLboolean GLboolean a
**But if you need a result
SYS_API fpreal32 SYSfloor(fpreal32 val)