FD.io VPP
v16.06
Vector Packet Processing
|
Linear Congruential Random Number Generator. More...
Go to the source code of this file.
Functions | |
always_inline u32 | random_u32 (u32 *seed) |
32-bit random number generator More... | |
int | test_random_main (unformat_input_t *input) |
always_inline u32 | random_u32_max (void) |
Maximum value returned by random_u32() More... | |
always_inline uword | random_default_seed (void) |
Default random seed (unix/linux user-mode) More... | |
always_inline u64 | random_u64 (u32 *seed) |
64-bit random number generator More... | |
always_inline uword | random_uword (u32 *seed) |
machine word size random number generator More... | |
always_inline f64 | random_f64 (u32 *seed) |
Generate f64 random number in the interval [0,1]. More... | |
always_inline u8 * | random_string (u32 *seed, uword len) |
Generate random character vector. 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.
always_inline uword random_default_seed | ( | void | ) |
always_inline f64 random_f64 | ( | u32 * | seed | ) |
always_inline u8* random_string | ( | u32 * | seed, |
uword | len | ||
) |
always_inline u32 random_u32 | ( | u32 * | seed | ) |
always_inline u32 random_u32_max | ( | void | ) |
Maximum value returned by random_u32()
Definition at line 77 of file random.h.
always_inline u64 random_u64 | ( | u32 * | seed | ) |
64-bit random number generator
created via two calls to random_u32(). Quick and dirty.
Definition at line 112 of file random.h.
always_inline uword random_uword | ( | u32 * | seed | ) |
int test_random_main | ( | unformat_input_t * | input | ) |