Skip to main content

random_unsigned_polynomials

Function random_unsigned_polynomials 

Source
pub fn random_unsigned_polynomials<T: PrimitiveUnsigned>(
    seed: Seed,
    mean_length_numerator: u64,
    mean_length_denominator: u64,
) -> RandomUnsignedPolynomialsFromUnsigneds<T>
Expand description

Generates random UnsignedPolynomials.

The coefficients are sampled from random_primitive_ints and the leading coefficient from random_positive_unsigneds, so each is uniform over its whole range — a u64 has no mean bit count to choose.

The lengths — the number of coefficients, which is one more than the degree, or zero for the zero polynomial — are sampled from a geometric distribution with mean mean_length_numerator / mean_length_denominator, so the zero polynomial is generated with the probability that that distribution gives to 0.

§Worst-case complexity per iteration

$T(i) = O(\ell)$

$M(i) = O(\ell)$

where $T$ is time, $M$ is additional memory, $i$ is the iteration number, $\ell$ is the number of coefficients of the $i$th output.

§Panics

Panics if mean_length_numerator or mean_length_denominator are zero or their ratio is greater than or equal to $2^{64}$.

§Examples

use malachite_base::iterators::prefix_to_string;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::unsigned_polynomial::random::random_unsigned_polynomials;

assert_eq!(
    prefix_to_string(random_unsigned_polynomials::<u64>(EXAMPLE_SEED, 1, 1), 5),
    "[6282517168718784610, 3854918945212287108*x+16126131237969988437, 3848495687584076941*x+16\
    908237734149745446, 8242875068444962379*x+10938355129926736414, 33570146165392012, ...]"
);