Function malachite_q::random::random_negative_rationals
source · pub fn random_negative_rationals(
seed: Seed,
mean_bits_numerator: u64,
mean_bits_denominator: u64
) -> NegativeRationals<RandomRationalsFromSingle<RandomNaturals<GeometricRandomNaturalValues<u64>>>> ⓘ
Expand description
Generates random negative Rational
s with a specified numerator and denominator mean bit
length.
The actual bit length is chosen from a geometric distribution with mean $m$, where $m$ is
mean_bits_numerator / mean_bits_denominator
; $m$ must be greater than 1. Then the numerator
and denominator are chosen from all positive Natural
s with that bit length. Finally, the
resulting Rational
is reduced and negated.
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_bits_numerator / mean_bits_denominator
.
§Panics
Panics if mean_bits_numerator
or mean_bits_denominator
are zero or if mean_bits_numerator <= mean_bits_denominator
.
§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::random::EXAMPLE_SEED;
use malachite_q::random::random_negative_rationals;
assert_eq!(
prefix_to_string(random_negative_rationals(EXAMPLE_SEED, 32, 1), 10),
"[-11/2, -89/27922830575, -46627409/3788983764809694, -8/11316951483471, \
-11/1005760138411689342464923704482, -948931/42716754, \
-81013760999253680590984897748479904878392/23, -1/97645164585502, -1558028859598/29, \
-200127331174844881647/4058622214797175252, ...]"
)