rte_random.h(3)
π rte_random.h β the cute lil random number page (man page 3, bestie) π
okay so welcome to rte_random.h(3) from the Library Functions Manual, and bestie, this one is genuinely so much fun β it's the random number generator header for RTE, and we're gonna go through every single function together, no skips, no shortcuts, periodt. π
β¨ NAME β¨
rte_random.h β that's it, that's the name, the whole vibe lives in this one header file π¦
πΈ SYNOPSIS πΈ
First thing, you gotta pull in the include, like so:
#include <stdint.h>
π«Ά Functions
void rte_srand (uint64_t seedval)uint64_t rte_rand (void)uint64_t rte_rand_max (uint64_t upper_bound)double rte_drand (void)
those are literally the four icons of this page and we're gonna meet each one π
π Detailed Description π
Pseudo-random Generators in RTE
yeah, that's the whole concept β RTE's pseudo-random generators.
Definition in file rte_random.h.
π Function Documentation π
π« void rte_srand (uint64_t seedval)
Seed the pseudo-random generator.
so the tea here is: the generator is automatically seeded by the EAL init with a timer value. cute, right? but the plot twist β it may need to be re-seeded by the user with a real random value. so if you want actual randomness instead of a timer vibe, that's on you bestie π
β οΈ okay important warning time: this function is not multi-thread safe in regards to otherrte_srand()calls, nor is it in relation to concurrentrte_rand(),rte_rand_max()orrte_drand()calls. so don't go wild with it from a bunch of threads at once, fr fr. π
Parameters
seedvalβ The value of the seed.
π uint64_t rte_rand (void )
Get a pseudo-random value.
π₯ caveat that matters: the generator is not cryptographically secure. so do NOT use this for secrets, passwords, crypto keys, anything like that. it's a vibe, not a vault. π«
rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, with the exception that they may not be called by multiple unregistered non-EAL threads in parallel. that's the one lil asterisk on the whole thing, iykyk π§
Returns
A pseudo-random value between 0 and (1<<64)-1.
π 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. so no sneaky bias, no weighting, just even distribution, we love to see it β¨
rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, with the exception that they may not be called by multiple unregistered non-EAL threads in parallel.
Parameters
upper_boundβ The upper bound of the generated number.
Returns
A pseudo-random value between 0 and (upper_bound-1).
π¦ double rte_drand (void )
Generates a pseudo-random floating point number.
This function returns a non-negative double-precision floating random number uniformly distributed over the interval [0.0, 1.0). so like, zero is in, one is out. half-open interval behavior, main character energy π
π₯ same caveat as before, ngl: the generator is not cryptographically secure. not for secrets, bestie, i'm serious π
rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, with the exception that they may not be called by multiple unregistered non-EAL threads in parallel.
Returns
A pseudo-random value between 0 and 1.0.
π Author π
Generated automatically by Doxygen for DPDK from the source code. no human wrote the prose, only the code was iconic π
and that's the whole page bestie!! πΈπβ¨ random numbers, seeded, bounded, floating, all of it, no notes, ate and left no crumbs π
love you, go rte_rand() responsibly π«Ά β this was DPDK, Version 25.11.3, page rte_random.h(3), and yes this was the Library Functions Manual the whole time ππ
π¦ where this page comes from
- ubuntu resolute: dpdk-doc 25.11.3-0ubuntu0.26.04.1 Β· BSD-3-Clause
- ubuntu stonking: dpdk-doc 25.11.3-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms