FD.io VPP  v16.06
Vector Packet Processing
random.h File Reference

Linear Congruential Random Number Generator. More...

+ Include dependency graph for random.h:
+ This graph shows which files directly or indirectly include this file:

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 u8random_string (u32 *seed, uword len)
 Generate random character vector. More...
 

Detailed Description

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.

Function Documentation

always_inline uword random_default_seed ( void  )

Default random seed (unix/linux user-mode)

Definition at line 85 of file random.h.

+ Here is the caller graph for this function:

always_inline f64 random_f64 ( u32 seed)

Generate f64 random number in the interval [0,1].

Definition at line 133 of file random.h.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

always_inline u8* random_string ( u32 seed,
uword  len 
)

Generate random character vector.

From the alphabet a-z, lower case. Returns a vector of the supplied length which is NOT guaranteed to be NULL-terminated. FIXME?

Definition at line 143 of file random.h.

+ Here is the call graph for this function:

always_inline u32 random_u32 ( u32 seed)

32-bit random number generator

Definition at line 68 of file random.h.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

always_inline u32 random_u32_max ( void  )

Maximum value returned by random_u32()

Definition at line 77 of file random.h.

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

always_inline uword random_uword ( u32 seed)

machine word size random number generator

Definition at line 124 of file random.h.

+ Here is the call graph for this function:

int test_random_main ( unformat_input_t input)

+ Here is the caller graph for this function: