Function malachite_nz::natural::random::random_naturals_less_than

source ·
pub fn random_naturals_less_than(
    seed: Seed,
    limit: Natural
) -> RandomNaturalsLessThan 
Expand description

Uniformly generates random Naturals 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

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is limit.significant_bits().

§Panics

Panics if limit is 0.

§Examples

use malachite_base::iterators::prefix_to_string;
use malachite_base::random::EXAMPLE_SEED;
use malachite_nz::natural::random::random_naturals_less_than;
use malachite_nz::natural::Natural;

assert_eq!(
    prefix_to_string(random_naturals_less_than(EXAMPLE_SEED, Natural::from(10u32)), 10),
    "[1, 7, 5, 7, 9, 2, 8, 2, 4, 6, ...]"
)