Function malachite_base::strings::random::random_strings
source · [−]pub fn random_strings(
seed: Seed,
mean_length_numerator: u64,
mean_length_denominator: u64
) -> StringsFromCharVecs<RandomVecs<char, GeometricRandomNaturalValues<u64>, RandomCharRange>>ⓘNotable traits for StringsFromCharVecs<I>impl<I: Iterator<Item = Vec<char>>> Iterator for StringsFromCharVecs<I> type Item = String;
Expand description
Generates random String
s.
The lengths of the String
s are sampled from a geometric distribution with a specified mean
$m$, equal to mean_length_numerator / mean_length_denominator
. $m$ must be greater than 0.
$$ P((c_0, c_1, \ldots, c_{n-1})) = \frac{m^n}{1112064^n(m+1)^{n+1}} $$
Expected complexity per iteration
$T(n) = O(m)$
$M(n) = O(m)$
where $T$ is time, $M$ is additional memory, and $m$ is
mean_length_numerator / mean_length_denominator
.
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
extern crate itertools;
use itertools::Itertools;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::strings::random::random_strings;
let ss = random_strings(EXAMPLE_SEED, 4, 1).take(10).collect_vec();
assert_eq!(
ss.iter().map(|cs| cs.as_str()).collect_vec().as_slice(),
&[
"",
"\u{81355}\u{a331d}\u{b707b}\u{1354b}\u{b16ac}𣙘\u{67377}\u{4aaa4}\u{a6d6e}\u{45616}\
\u{7725f}\u{41e2d}\u{d6b59}\u{de165}",
"\u{c2d29}\u{695af}\u{98fd7}\u{10ca51}",
"\u{bec46}\u{c0bec}\u{cb677}\u{71318}",
"\u{755e1}",
"",
"𫮜\u{a2f84}柂\u{f5560}\u{6737b}",
"\u{8442e}\u{a6883}",
"\u{49cf2}\u{32d2b}\u{1e6e5}\u{1084bd}",
""
]
);