Function malachite_nz::natural::random::uniform_random_natural_range
source · pub fn uniform_random_natural_range(
seed: Seed,
a: Natural,
b: Natural
) -> UniformRandomNaturalRange ⓘ
Expand description
Uniformly generates random Natural
s in the half-open interval $[a, b)$.
$a$ must be less than $b$.
$$ P(x) = \begin{cases} \frac{1}{b-a} & \text{if} \quad a \leq x < b, \\ 0 & \text{otherwise}. \end{cases} $$
The output length is infinite.
§Expected complexity per iteration
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is b.significant_bits()
.
§Panics
Panics if $a \geq b$.
§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::random::EXAMPLE_SEED;
use malachite_nz::natural::random::uniform_random_natural_range;
use malachite_nz::natural::Natural;
assert_eq!(
prefix_to_string(
uniform_random_natural_range(
EXAMPLE_SEED,
Natural::from(10u32),
Natural::from(100u32)
),
10
),
"[97, 17, 94, 37, 56, 32, 96, 11, 17, 39, ...]"
)