[#absl-Uniform-0e2] = xref:absl.adoc[absl]::Uniform :relfileprefix: ../ :mrdocs: Produces random values of type `T` uniformly distributed in an interval. == Synopsis Declared in `<absl/random/distributions.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename R = void, typename TagType, typename URBG> R Uniform( TagType tag, URBG&& urbg, R lo, R hi) requires !std::is_same_v<R, void>; ---- == Description `absl::Uniform()` produces random values of type `T` uniformly distributed in a defined interval {lo, hi}. The interval `tag` defines the type of interval which should be one of the following possible values: * `absl::IntervalOpenOpen` * `absl::IntervalOpenClosed` * `absl::IntervalClosedOpen` * `absl::IntervalClosedClosed` where "open" refers to an exclusive value (excluded) from the output, while "closed" refers to an inclusive value (included) from the output. In the absence of an explicit return type `T`, `absl::Uniform()` will deduce the return type based on the provided endpoint arguments {A lo, B hi}. Given these endpoints, one of {A, B} will be chosen as the return type, if a type can be implicitly converted into the other in a lossless way. The lack of any such implicit conversion between {A, B} will produce a compile‐time error See https://en.wikipedia.org/wiki/Uniform_distribution_(continuous) Example: absl::BitGen bitgen; // Produce a random float value between 0.0 and 1.0, inclusive auto x = absl::Uniform(absl::IntervalClosedClosed, bitgen, 0.0f, 1.0f); // The most common interval of `absl::IntervalClosedOpen` is available by // default: auto x = absl::Uniform(bitgen, 0.0f, 1.0f); // Return‐types are typically inferred from the arguments, however callers // can optionally provide an explicit return‐type to the template. auto x = absl::Uniform<float>(bitgen, 0, 1); == Return Value A random value uniformly distributed in the interval. == Parameters [cols="1,4"] |=== | Name| Description | *tag* | The interval tag selecting which endpoints are included. | *urbg* | The uniform random bit generator. | *lo* | The lower bound of the interval. | *hi* | The upper bound of the interval. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#