Function malachite_nz::integer::random::random_negative_integers

source ·
pub fn random_negative_integers(
    seed: Seed,
    mean_bits_numerator: u64,
    mean_bits_denominator: u64
) -> RandomIntegers<GeometricRandomNegativeSigneds<i64>> 
Expand description

Generates random negative Integers whose absolute values have a specified 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 an Integer is chosen uniformly among all positive Integers with that bit length, and negated. The resulting distribution resembles a negated Pareto distribution. It has no mean or higher-order statistics (unless $m < 2$, which is not typical).

$$ P(n) = \begin{cases} 0 & \text{if} \quad n \geq 0 ,\\ \frac{1}{m} \left ( \frac{m-1}{2m} \right ) ^ {\lfloor \log_2 (-n) \rfloor} & \text{otherwise}. \end{cases} $$

The output length is infinite.

§Expected complexity per iteration

$T(n, m) = O(n + m)$

$M(n, m) = O(n / m)$

where $T$ is time, $M$ is additional memory, $n$ is mean_precision_numerator, and $m$ is mean_precision_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_nz::integer::random::random_negative_integers;
use malachite_nz::integer::Integer;

assert_eq!(
    prefix_to_string(random_negative_integers(EXAMPLE_SEED, 32, 1), 10),
    "[-22, -4, -178, -55845661150, -93254818, -7577967529619388, -8, -11316951483471, -11, \
    -1005760138411689342464923704482, ...]"
)