[RFT v2 1/3] random: add rte_rand_float()
Morten Brørup
mb at smartsharesystems.com
Wed May 25 17:26:06 CEST 2022
> From: Mattias Rönnblom [mailto:mattias.ronnblom at ericsson.com]
> Sent: Wednesday, 25 May 2022 16.46
>
> On 2022-05-25 00:18, Stephen Hemminger wrote:
> > The PIE code and other applications can benefit from having a
> > fast way to get a random floating point value. This new function
> > is equivalent to erand48_r in the standard library.
> >
> > +/**
> > + * @warning
> > + * @b EXPERIMENTAL: this API may change without prior notice
> > + *
> > + * Generates a pseudo-random floating point number.
> > + *
> > + * This function returns a nonnegative double-precison floating
> random
> > + * number uniformly distributed over the interval [0.0, 1.0).
> > + *
> > + * If called from lcore threads, this function is thread-safe.
> > + *
> > + * @return
> > + * A pseudo-random value between 0 and 1.0.
> > + */
> > +__rte_experimental
> > +double rte_rand_float(void);
> > +
>
> Newline after "double" missing.
>
> I would call it something else than "float", in particular since it
> doesn't return "float" but a "double" type floating point value.
>
> rte_drand() maybe? Short, but might be confused with rte_rand(), given
> the visual similarity. I still I would still prefer that over
> rte_rand_double().
Although we use foo32() and foo64() for many functions returning uint32_t/uint64_t, I don't think we need a common (and preferably short) postfix for functions returning double. Such functions should be rare.
So:
+1 to rte_drand() - it resembles drand48() in stdlib.h.
More information about the dev
mailing list