1 #ifndef GUARD_GGEMS_RANDOMS_GGEMSKISSENGINE_HH
2 #define GUARD_GGEMS_RANDOMS_GGEMSKISSENGINE_HH
34 #ifdef __OPENCL_C_VERSION__
61 random->prng_state_2_[index] ^= (random->prng_state_2_[index] << 5);
62 random->prng_state_2_[index] ^= (random->prng_state_2_[index] >> 7);
63 random->prng_state_2_[index] ^= (random->prng_state_2_[index] << 22);
65 GGint t = random->prng_state_3_[index] + random->prng_state_4_[index] + random->prng_state_5_[index];
67 random->prng_state_3_[index] = random->prng_state_4_[index];
68 random->prng_state_5_[index] = t < 0;
69 random->prng_state_4_[index] = t & 2147483647;
70 random->prng_state_1_[index] += 1411392427;
72 return ((
GGfloat)(random->prng_state_1_[index] + random->prng_state_2_[index] + random->prng_state_4_[index])
74 / 4294967295.0) * (1.0f - 1.0f/(1<<23));
93 GGfloat position = 0.0, poisson_value = 0.0, poisson_sum = 0.0;
94 GGfloat value = 0.0, y = 0.0, t = 0.0;
99 position = KissUniform(random, index);
101 while ((1.f-position) < 2.e-7f);
103 poisson_value = exp(-mean);
104 poisson_sum = poisson_value;
106 while ((poisson_sum <= position) && (number < 40000.)) {
108 poisson_value *= mean/number;
110 if ((poisson_sum + poisson_value) == poisson_sum)
break;
111 poisson_sum += poisson_value;
116 t = sqrt(-2.f*log(KissUniform(random, index)));
117 y = 2.f *
PI * KissUniform(random, index);
119 value = mean + t*sqrt(mean) + 0.5f;
121 if (value <= 0.)
return (
GGuint)0;
123 return (value >= 2.e9f) ? (
GGint)2.e9f : (
GGint)value;
141 GGfloat u1 = KissUniform(random, index);
142 GGfloat u2 = KissUniform(random, index);
143 GGfloat r1 = sqrt(-2.0f * log(u1));
146 return sigma * r1 * cos(r2);
151 #endif // End of GUARD_GGEMS_RANDOMS_GGEMSKISSENGINE_HH