35static uint32_t
MT[624];
61 fd = open(
"/dev/urandom",
64 i =
sizeof( uint32_t ) * 624;
65 if ( read( fd, &
MT, i ) == (ssize_t)i )
78 for (
int j = 0; j < 10;
95 gettimeofday( &tv, NULL );
96 i = tv.tv_sec * 1000000 + tv.tv_usec;
100 i = tb.time * 1000 + tb.millitm;
102#error "Feature needs implementation on this Operating System for Naev to work."
115 for (
int i = 1; i < 624; i++ )
116 MT[i] = 1812433253 * (
MT[i - 1] ^ ( ( (
MT[i - 1] ) ) + i ) >> 30 );
127 for (
int i = 0; i < 624; i++ ) {
128 mt_y = (
MT[i] & 0x80000000 ) + ( (
MT[i] % 624 ) & 0x7FFFFFFF );
130 MT[i] = (
MT[( i + 397 ) % 624] ^ (
mt_y >> 1 ) ) ^ 2567483615U;
132 MT[i] =
MT[( i + 397 ) % 624] ^ (
mt_y >> 1 );
151 mt_y ^= (
mt_y << 7 ) & 2636928640U;
152 mt_y ^= (
mt_y << 15 ) & 4022730752U;
177static double m_div = (double)( 0xFFFFFFFF );
205 const double b1 = 0.319381530;
206 const double b2 = -0.356563782;
207 const double b3 = 1.781477937;
208 const double b4 = -1.821255978;
209 const double b5 = 1.330274429;
210 const double p = 0.2316419;
211 const double c = 0.39894228;
213 t = 1. / ( 1. + p *
FABS( x ) );
214 series = ( 1. -
c * exp( -x * x / 2. ) * t *
215 ( t * ( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 ) );
216 return ( x > 0. ) ? 1. - series : series;
245static const double a[] = {
246 -3.969683028665376e+01,
247 2.209460984245205e+02,
248 -2.759285104469687e+02,
249 1.383577518672690e+02,
250 -3.066479806614716e+01,
251 2.506628277459239e+00 };
252static const double b[] = {
253 -5.447609879822406e+01, 1.615858368580409e+02, -1.556989798598866e+02,
254 6.680131188771972e+01,
255 -1.328068155288572e+01 };
256static const double c[] = {
257 -7.784894002430293e-03,
258 -3.223964580411365e-01,
259 -2.400758277161838e+00,
260 -2.549732539343734e+00,
261 4.374664141464968e+00,
262 2.938163982698783e+00 };
263static const double d[] = {
264 7.784695709041462e-03, 3.224671290700398e-01, 2.445134137142996e+00,
265 3.754408661907416e+00 };
270 double x, e, u, q, r;
274 if ( ( p < 0 ) || ( p > 1 ) ) {
277 }
else if ( p == 0. ) {
280 }
else if ( p == 1. ) {
285 else if ( p <
LOW ) {
287 q = sqrt( -2 * log( p ) );
288 x = ( ( ( ( (
c[0] * q +
c[1] ) * q +
c[2] ) * q +
c[3] ) * q +
c[4] ) *
291 ( ( ( (
d[0] * q +
d[1] ) * q +
d[2] ) * q +
d[3] ) * q + 1 );
292 }
else if ( p >
HIGH ) {
294 q = sqrt( -2 * log( 1 - p ) );
295 x = -( ( ( ( (
c[0] * q +
c[1] ) * q +
c[2] ) * q +
c[3] ) * q +
c[4] ) *
298 ( ( ( (
d[0] * q +
d[1] ) * q +
d[2] ) * q +
d[3] ) * q + 1 );
303 x = ( ( ( ( ( a[0] * r + a[1] ) * r + a[2] ) * r + a[3] ) * r + a[4] ) *
307 ( ( ( ( ( b[0] * r + b[1] ) * r + b[2] ) * r + b[3] ) * r + b[4] ) *
313 e = 0.5 * erfc( -x / M_SQRT2 ) - p;
314 u = e * 2.5066282746310002 * exp( ( x * x ) / 2 );
315 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.