Produces random integral values whose logarithm is uniformly distributed.
Synopsis
Declared in <absl/random/distributions.h>
template<
typename IntType,
typename URBG>
IntType
LogUniform(
URBG&& urbg,
IntType lo,
IntType hi,
IntType base = 2);
Description
absl::LogUniform produces random values distributed where the log to a given base of all values is uniform in a closed interval [lo, hi]. T must be an integral type, but may be inferred from the types of lo and hi.
I.e., LogUniform(0, n, b) is uniformly distributed across buckets [0], [1, b‐1], [b, bˆ2‐1].. [bˆ(k‐1), (bˆk)‐1].. [bˆfloor(log(n, b)), n] and is uniformly distributed within each bucket.
The resulting probability density is inversely related to bucket size, though values in the final bucket may be more likely than previous values. (In the extreme case where n = bˆi the final value will be tied with zero as the most probable result.
If lo is nonzero then this distribution is shifted to the desired interval, so LogUniform(lo, hi, b) is equivalent to LogUniform(0, hi‐lo, b)+lo.
See https://en.wikipedia.org/wiki/Reciprocal_distribution
Example:
absl::BitGen bitgen; ... int v = absl::LogUniform(bitgen, 0, 1000);
Return Value
A random value drawn from the log‐uniform distribution.
Parameters
Name |
Description |
urbg |
The uniform random bit generator. |
lo |
The inclusive lower bound of the interval. |
hi |
The inclusive upper bound of the interval. |
base |
The logarithm base determining the bucket sizes. |
Created with MrDocs