Handles all the random number logic.
More...
#include "rng.h"
#include "log.h"
Go to the source code of this file.
|
| #define | LOW 0.02425 |
| |
| #define | HIGH 0.97575 |
| |
|
| static uint32_t | rng_timeEntropy (void) |
| | Uses time as a source of entropy.
|
| |
| static void | mt_initArray (uint32_t seed) |
| | Generates the initial mersenne twister based on seed.
|
| |
| static void | mt_genArray (void) |
| | Generates a new set of random numbers for the mersenne twister.
|
| |
| static uint32_t | mt_getInt (void) |
| | Gets the next int.
|
| |
| void | rng_init (void) |
| | Initializes the random subsystem.
|
| |
| unsigned int | randint (void) |
| | Gets a random integer.
|
| |
| double | randfp (void) |
| | Gets a random float between 0 and 1 (inclusive).
|
| |
| double | Normal (double x) |
| | Calculates the Normal distribution.
|
| |
| double | NormalInverse (double p) |
| | Calculates the inverse of the normal.
|
| |
|
| static uint32_t | MT [624] |
| |
| static uint32_t | mt_y |
| |
| static int | mt_pos = 0 |
| |
| static double | m_div = (double)(0xFFFFFFFF) |
| |
| static const double | a [] |
| |
| static const double | b [] |
| |
| static const double | c [] |
| |
| static const double | d [] |
| |
Handles all the random number logic.
Random numbers are currently generated using the mersenne twister.
Definition in file rng.c.
◆ HIGH
High area threshold.
Definition at line 281 of file rng.c.
◆ LOW
Low area threshold.
Definition at line 280 of file rng.c.
◆ mt_genArray()
| static void mt_genArray |
( |
void | | ) |
|
|
static |
Generates a new set of random numbers for the mersenne twister.
Definition at line 127 of file rng.c.
◆ mt_getInt()
| static uint32_t mt_getInt |
( |
void | | ) |
|
|
static |
Gets the next int.
- Returns
- A random 4 byte number.
Definition at line 146 of file rng.c.
◆ mt_initArray()
| static void mt_initArray |
( |
uint32_t | seed | ) |
|
|
static |
Generates the initial mersenne twister based on seed.
Definition at line 114 of file rng.c.
◆ Normal()
| double Normal |
( |
double | x | ) |
|
Calculates the Normal distribution.
Calculates N(x) where N is the normal distribution.
Approximates to a power series:
N(x) = 1 - n(x)*(b1*t + b2*t^2 + b3*t^3 + b4*t^4 + b5*t^5) + Err where t = 1 / (1 + 0.2316419*x)
Maximum absolute error is 7.5e^-8.
- Parameters
-
| x | Value to calculate the normal of. |
- Returns
- The value of the Normal.
Definition at line 203 of file rng.c.
◆ NormalInverse()
| double NormalInverse |
( |
double | p | ) |
|
Calculates the inverse of the normal.
Lower tail quantile for standard normal distribution function.
This function returns an approximation of the inverse cumulative standard normal distribution function. I.e., given P, it returns an approximation to the X satisfying P = Pr{Z <= X} where Z is a random variable from the standard normal distribution.
The algorithm uses a minimax approximation by rational functions and the result has a relative error whose absolute value is less than 1.15e-9.
Author: Peter J. Acklam Time-stamp: 2002-06-09 18:45:44 +0200 E-mail: jackl.nosp@m.am@m.nosp@m.ath.u.nosp@m.io.n.nosp@m.o WWW URL: http://www.math.uio.no/~jacklam
C implementation adapted from Peter's Perl version.
Original algorithm from http://home.online.no/~pjacklam/notes/invnorm/ .
Definition at line 282 of file rng.c.
◆ randfp()
Gets a random float between 0 and 1 (inclusive).
- Returns
- A random float between 0 and 1 (inclusive).
Definition at line 180 of file rng.c.
◆ randint()
| unsigned int randint |
( |
void | | ) |
|
Gets a random integer.
- Returns
- A random integer.
Definition at line 167 of file rng.c.
◆ rng_init()
Initializes the random subsystem.
Definition at line 56 of file rng.c.
◆ rng_timeEntropy()
| static uint32_t rng_timeEntropy |
( |
void | | ) |
|
|
static |
Uses time as a source of entropy.
- Returns
- A 4 byte entropy seed.
Definition at line 92 of file rng.c.
Initial value:=
{
-3.969683028665376e+01,
2.209460984245205e+02,
-2.759285104469687e+02,
1.383577518672690e+02,
-3.066479806614716e+01,
2.506628277459239e+00
}
Inverse normal coefficients.
Definition at line 247 of file rng.c.
Initial value:=
{
-5.447609879822406e+01,
1.615858368580409e+02,
-1.556989798598866e+02,
6.680131188771972e+01,
-1.328068155288572e+01
}
Inverse normal coefficients.
Definition at line 256 of file rng.c.
Initial value:=
{
-7.784894002430293e-03,
-3.223964580411365e-01,
-2.400758277161838e+00,
-2.549732539343734e+00,
4.374664141464968e+00,
2.938163982698783e+00
}
Inverse normal coefficients.
Definition at line 264 of file rng.c.
Initial value:=
{
7.784695709041462e-03,
3.224671290700398e-01,
2.445134137142996e+00,
3.754408661907416e+00
}
Inverse normal coefficients.
Definition at line 273 of file rng.c.
◆ m_div
| double m_div = (double)(0xFFFFFFFF) |
|
static |
Number to divide by.
Definition at line 179 of file rng.c.
◆ MT
Mersenne twister state.
Definition at line 38 of file rng.c.
◆ mt_pos
Current number being used.
Definition at line 40 of file rng.c.
◆ mt_y
Internal mersenne twister variable.
Definition at line 39 of file rng.c.