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 other rte_srand() calls, nor is it in relation to concurrent rte_rand(), rte_rand_max() or rte_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