Function malachite_base::num::random::random_unsigneds_less_than
source · [−]pub fn random_unsigneds_less_than<T: PrimitiveUnsigned>(
seed: Seed,
limit: T
) -> RandomUnsignedsLessThan<T>ⓘNotable traits for RandomUnsignedsLessThan<T>impl<T: PrimitiveUnsigned> Iterator for RandomUnsignedsLessThan<T> type Item = T;
Expand description
Uniformly generates random unsigned integers less than a positive limit.
$$
P(x) = \begin{cases}
\frac{1}{\ell} & \text{if} \quad x < \ell, \\
0 & \text{otherwise,}
\end{cases}
$$
where $\ell$ is limit
.
The output length is infinite.
Expected complexity per iteration
Constant time and additional memory.
Panics
Panics if limit
is 0.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::random_unsigneds_less_than;
use malachite_base::random::EXAMPLE_SEED;
assert_eq!(
prefix_to_string(random_unsigneds_less_than::<u8>(EXAMPLE_SEED, 10), 10),
"[1, 7, 5, 4, 6, 4, 2, 8, 1, 7, ...]"
)