38static uint32_t
MT[624];
64 fd = open(
"/dev/urandom", O_RDONLY);
66 i =
sizeof(uint32_t)*624;
67 if (read( fd, &
MT, i ) == (ssize_t)i)
97 gettimeofday( &tv, NULL );
98 i = tv.tv_sec * 1000000 + tv.tv_usec;
102 i = tb.time * 1000 + tb.millitm;
104#error "Feature needs implementation on this Operating System for Naev to work."
117 for (
int i=1; i<624; i++)
118 MT[i] = 1812433253 * (
MT[i-1] ^ (((
MT[i-1])) + i) >> 30);
129 for (
int i=0; i<624; i++ ) {
130 mt_y = (
MT[i] & 0x80000000) + ((
MT[i] % 624) & 0x7FFFFFFF);
132 MT[i] = (
MT[(i+397) % 624] ^ (
mt_y >> 1)) ^ 2567483615U;
134 MT[i] =
MT[(i+397) % 624] ^ (
mt_y >> 1);
179static double m_div = (double)(0xFFFFFFFF);
207 const double b1 = 0.319381530;
208 const double b2 = -0.356563782;
209 const double b3 = 1.781477937;
210 const double b4 = -1.821255978;
211 const double b5 = 1.330274429;
212 const double p = 0.2316419;
213 const double c = 0.39894228;
215 t = 1. / ( 1. + p *
FABS(x) );
216 series = (1. -
c * exp( -x * x / 2. ) * t *
217 ( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 ));
218 return (x > 0.) ? 1. - series : series;
247static const double a[] =
249 -3.969683028665376e+01,
250 2.209460984245205e+02,
251 -2.759285104469687e+02,
252 1.383577518672690e+02,
253 -3.066479806614716e+01,
254 2.506628277459239e+00
256static const double b[] =
258 -5.447609879822406e+01,
259 1.615858368580409e+02,
260 -1.556989798598866e+02,
261 6.680131188771972e+01,
262 -1.328068155288572e+01
264static const double c[] =
266 -7.784894002430293e-03,
267 -3.223964580411365e-01,
268 -2.400758277161838e+00,
269 -2.549732539343734e+00,
270 4.374664141464968e+00,
271 2.938163982698783e+00
273static const double d[] =
275 7.784695709041462e-03,
276 3.224671290700398e-01,
277 2.445134137142996e+00,
278 3.754408661907416e+00
284 double x, e, u, q, r;
288 if ((p < 0) || (p > 1)) {
304 x = (((((
c[0]*q+
c[1])*q+
c[2])*q+
c[3])*q+
c[4])*q+
c[5]) /
305 ((((
d[0]*q+
d[1])*q+
d[2])*q+
d[3])*q+1);
309 q = sqrt(-2*log(1-p));
310 x = -(((((
c[0]*q+
c[1])*q+
c[2])*q+
c[3])*q+
c[4])*q+
c[5]) /
311 ((((
d[0]*q+
d[1])*q+
d[2])*q+
d[3])*q+1);
317 x = (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q /
318 (((((b[0]*r+b[1])*r+b[2])*r+b[3])*r+b[4])*r+1);
322 e = 0.5 * erfc(-x / M_SQRT2) - p;
323 u = e * 2.5066282746310002 * exp((x*x)/2);
324 x = x - u/(1 + x*u/2);
Header file with generic functions and naev-specifics.
static void mt_initArray(uint32_t seed)
Generates the initial mersenne twister based on seed.
double Normal(double x)
Calculates the Normal distribution.
double randfp(void)
Gets a random float between 0 and 1 (inclusive).
static uint32_t mt_getInt(void)
Gets the next int.
double NormalInverse(double p)
Calculates the inverse of the normal.
void rng_init(void)
Initializes the random subsystem.
static void mt_genArray(void)
Generates a new set of random numbers for the mersenne twister.
unsigned int randint(void)
Gets a random integer.
static uint32_t rng_timeEntropy(void)
Uses time as a source of entropy.