Produces random integral values whose logarithm is uniformly distributed.
Declared in <absl/random/distributions.h>
template<
typename IntType,
typename URBG>
IntType
LogUniform(
URBG&& urbg,
IntType lo,
IntType hi,
IntType base = 2);
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);
A random value drawn from the log-uniform distribution.
| 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. |