FD.io VPP
v20.09-64-g4f7b92f0a
Vector Packet Processing
|
Linear Congruential Random Number Generator. More...
Go to the source code of this file.
Functions | |
static u32 | random_u32 (u32 *seed) |
32-bit random number generator More... | |
int | test_random_main (unformat_input_t *input) |
static u32 | random_u32_max (void) |
Maximum value returned by random_u32() More... | |
static uword | random_default_seed (void) |
Default random seed (unix/linux user-mode) More... | |
static u64 | random_u64 (u64 *seed) |
64-bit random number generator Again, constants courtesy of Donald Knuth. More... | |
static uword | random_uword (u32 *seed) |
machine word size random number generator More... | |
static f64 | random_f64 (u32 *seed) |
Generate f64 random number in the interval [0,1]. More... | |
static u8 * | random_string (u32 *seed, uword len) |
Generate random character vector. More... | |
f64 | clib_chisquare (u64 *values) |
Compute the X2 test statistic for a vector of counts. More... | |
Linear Congruential Random Number Generator.
This specific random number generator is described in "Numerical Recipes in C", 2nd edition, page 284. If you need random numbers with really excellent statistics, take a look at Chapter 7...
By definition, a linear congruential random number generator is of the form: rand[i+1] = a*rand[i] + c (mod m) for specific values of (a,c,m).
In this case, choose m = 2**32 and use the low-order 32-bits of the 64-bit product a*N[i]. Knuth suggests the use of a=1664525, H.W. Lewis has tested C=1013904223 extensively. This routine is reputedly as good as any 32-bit LCRN, and costs only a single multiply-add.
Several variants: 32/64-bit, machine word width, f64 on the closed interval [0,1].
Definition in file random.h.
Compute the X2 test statistic for a vector of counts.
Each value element corresponds to a histogram bucket.
Typical use-case: test the hypothesis that a set of octets are uniformly distributed (aka random).
In a 1-dimensional use-case, the result should be compared with the critical value from chi square tables with vec_len(values) - 1 degrees of freedom.
[in] | values | vector of histogram bucket values |
Definition at line 65 of file random.c.
|
inlinestatic |
|
inlinestatic |
Maximum value returned by random_u32()
Definition at line 80 of file random.h.
int test_random_main | ( | unformat_input_t * | input | ) |