pub fn random_rationals_with_denominator_range(
    seed: Seed,
    d: Natural,
    a: Rational,
    b: Rational,
    mean_numerator_bits_numerator: u64,
    mean_numerator_bits_denominator: u64
) -> RationalsWithDenominator<RandomIntegerRange> 
Expand description

Generates random Rationals in the half-open interval $[a, b)$ and with a specific denominator.

In general, the Rationals are not generated uniformly. Instead, Rationals whose numerators have smaller bit lengths are generated more frequently.

The distribution of generated values is parametrized by a number $m$, given by mean_numerator_bits_numerator / mean_numerator_bits_denominator. It is not actually the mean bit length of the numerators, though it approaches the mean bit length of the numerators minus $\lceil ad \right$ as $\log (b/a)$ approaches infinity. $m$ cannot be 0, and must be greater than the bit length of the numerator of the generated Rational with the smallest absolute value, but it may be arbitrarily large. The smaller it is, the more quickly the probabilities decrease as bit length increases. The larger it is, the more closely the distribution approaches a uniform distribution over the bit lengths.

The output length is infinite.

§Expected complexity per iteration

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is mean_numerator_bits_numerator / mean_numerator_bits_denominator.

§Panics

Panics if $a \geq b$, if mean_bits_numerator or mean_bits_denominator are zero, if their ratio is less than or equal to the bit length of the Rational with smallest absolute numerator in the range, or if they are too large and manipulating them leads to arithmetic overflow.

§Examples

use malachite_base::iterators::prefix_to_string;
use malachite_base::random::EXAMPLE_SEED;
use malachite_nz::natural::Natural;
use malachite_q::random::random_rationals_with_denominator_range;
use malachite_q::Rational;

assert_eq!(
    prefix_to_string(
        random_rationals_with_denominator_range(
            EXAMPLE_SEED,
            Natural::from(100u32),
            Rational::from_unsigneds(1u32, 3),
            Rational::from_unsigneds(1u32, 2),
            3,
            1
        ),
        10
    ),
    "[41/100, 43/100, 41/100, 41/100, 39/100, 41/100, 49/100, 41/100, 41/100, 39/100, ...]"
)