naev 0.12.6
rng.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
11#define RNG( L, H ) \
12 ( ( ( L ) > ( H ) ) ? RNG_BASE( ( H ), ( L ) ) \
13 : RNG_BASE( ( L ), ( H ) ) ) /* L <= RNG <= H */
19#define RNG_BASE( L, H ) \
20 ( (int)L + (int)( (double)( H - L + 1 ) * randfp() ) ) /* L <= RNG <= H */
24#define RNGF() ( randfp() ) /* 0. <= RNGF <= 1. */
30#define RNG_1SIGMA() \
31 NormalInverse( 0.158655255 + RNGF() * ( 1. - 0.158655255 * 2. ) )
37#define RNG_2SIGMA() \
38 NormalInverse( 0.022750132 + RNGF() * ( 1. - 0.022750132 * 2. ) )
44#define RNG_3SIGMA() \
45 NormalInverse( 0.0013498985 + RNGF() * ( 1. - 0.0013498985 * 2. ) )
46
47/* Init */
48void rng_init( void );
49
50/* Random functions */
51unsigned int randint( void );
52double randfp( void );
53
54/* Probability functions */
55double Normal( double x );
56double NormalInverse( double p );
double Normal(double x)
Calculates the Normal distribution.
Definition rng.c:201
double randfp(void)
Gets a random float between 0 and 1 (inclusive).
Definition rng.c:178
double NormalInverse(double p)
Calculates the inverse of the normal.
Definition rng.c:268
void rng_init(void)
Initializes the random subsystem.
Definition rng.c:53
unsigned int randint(void)
Gets a random integer.
Definition rng.c:165