Skip to main content

random_unsigned_vectors

Function random_unsigned_vectors 

Source
pub fn random_unsigned_vectors<T: PrimitiveUnsigned>(
    seed: Seed,
    mean_length_numerator: u64,
    mean_length_denominator: u64,
) -> RandomUnsignedVectors<RandomVecs<T, GeometricRandomNaturalValues<u64>, RandomPrimitiveInts<T>>> ⓘ
Expand description

Generates random UnsignedVectors.

The elements are sampled from random_primitive_ints, so each is uniform over its whole range. The dimensions are sampled from a geometric distribution with mean mean_length_numerator / mean_length_denominator, so the 0-dimensional vector is generated with the probability that that distribution gives to 0.

The output length is infinite.

§Worst-case complexity per iteration

$T(i) = O(n)$

$M(i) = O(n)$

where $T$ is time, $M$ is additional memory, $i$ is the iteration number, and $n$ is the dimension of the $i$th output.

§Panics

Panics if mean_length_numerator or mean_length_denominator are zero, or if, after being reduced to lowest terms, their sum 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_vector::random::random_unsigned_vectors;

assert_eq!(
    prefix_to_string(random_unsigned_vectors::<u8>(EXAMPLE_SEED, 2, 1), 5),
    "[(85, 11, 136, 200, 235, 134), (203), (223, 38, 235, 217, 177, 162, 32, 166), (234), \
    (30, 218, 90, 106, 9, 216, 204, 151, 213, 97, 253, 78, 91, 39), ...]"
);