DPDK  20.02.1
Functions
rte_random.h File Reference
#include <stdint.h>
#include <rte_compat.h>

Go to the source code of this file.

Functions

void rte_srand (uint64_t seedval)
 
uint64_t rte_rand (void)
 
__rte_experimental uint64_t rte_rand_max (uint64_t upper_bound)
 

Detailed Description

Pseudo-random Generators in RTE

Definition in file rte_random.h.

Function Documentation

void rte_srand ( uint64_t  seedval)

Seed the pseudo-random generator.

The generator is automatically seeded by the EAL init with a timer value. It may need to be re-seeded by the user with a real random value.

This function is not multi-thread safe in regards to other rte_srand() calls, nor is it in relation to concurrent rte_rand() calls.

Parameters
seedvalThe value of the seed.
uint64_t rte_rand ( void  )

Get a pseudo-random value.

The generator is not cryptographically secure.

If called from lcore threads, this function is thread-safe.

Returns
A pseudo-random value between 0 and (1<<64)-1.
Examples:
examples/ipsec-secgw/sa.c.
__rte_experimental uint64_t rte_rand_max ( uint64_t  upper_bound)

Generates a pseudo-random number with an upper bound.

This function returns an uniformly distributed (unbiased) random number less than a user-specified maximum value.

If called from lcore threads, this function is thread-safe.

Parameters
upper_boundThe upper bound of the generated number.
Returns
A pseudo-random value between 0 and (upper_bound-1).