Module malachite_base::vecs::random
source · Expand description
Iterators that generate Vec
s randomly.
random_vecs_length_2
use itertools::Itertools;
use malachite_base::chars::random::random_char_inclusive_range;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::vecs::random::random_vecs_length_2;
let xss = random_vecs_length_2(
EXAMPLE_SEED,
&|seed| random_char_inclusive_range(seed, 'a', 'c'),
&|seed| random_char_inclusive_range(seed, 'x', 'z'),
)
.take(20)
.collect_vec();
assert_eq!(
xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&['b', 'z'],
&['b', 'x'],
&['b', 'z'],
&['b', 'y'],
&['c', 'x'],
&['a', 'z'],
&['a', 'z'],
&['a', 'z'],
&['c', 'z'],
&['a', 'y'],
&['c', 'x'],
&['a', 'x'],
&['c', 'z'],
&['a', 'z'],
&['c', 'x'],
&['c', 'x'],
&['c', 'y'],
&['b', 'y'],
&['a', 'x'],
&['c', 'x']
]
);
random_vecs_fixed_length_2_inputs
use itertools::Itertools;
use malachite_base::chars::random::{random_ascii_chars, random_char_inclusive_range};
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::strings::ToDebugString;
use malachite_base::vecs::random::random_vecs_fixed_length_2_inputs;
// We are generating length-3 `Vec`s of `char`s using two input iterators. The first iterator
// (with index 0) produces random ASCII `char`s, and the second (index 1) produces the three
// `char`s `'x'`, `'y'`, and `'z'`, uniformly at random. The elements of `output_types` are 0,
// 1, and 0, meaning that the first element of the output `Vec`s will be taken from iterator 0,
// the second element from iterator 1, and the third also from iterator 0.
let xss = random_vecs_fixed_length_2_inputs(
EXAMPLE_SEED,
&random_ascii_chars,
&|seed| random_char_inclusive_range(seed, 'x', 'z'),
&[0, 1, 0],
)
.take(20)
.collect_vec();
assert_eq!(
xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&['U', 'z', '\u{16}'],
&[' ', 'x', 'D'],
&['<', 'z', ']'],
&['a', 'y', 'e'],
&['_', 'x', 'M'],
&[',', 'z', 'O'],
&['\u{1d}', 'z', 'V'],
&['(', 'z', '\u{10}'],
&['&', 'z', 'U'],
&['{', 'y', 'P'],
&['-', 'x', 'K'],
&['Z', 'x', '\u{4}'],
&['X', 'z', '\u{19}'],
&['_', 'z', ','],
&['\u{1d}', 'x', ','],
&['?', 'x', '\''],
&['[', 'y', 'N'],
&['|', 'y', '}'],
&['*', 'x', '\u{15}'],
&['z', 'x', 't']
]
);
Structs
This documentation applies not only to
RandomFixedLengthVecs2Inputs
, but also to
RandomFixedLengthVecs3Inputs
, RandomFixedLengthVecs4Inputs
, and so on. See
random_vecs_fixed_length
for more information.Generates random
Vec
s of a given length using elements from a single iterator.Generates random
Vec
s using elements from an iterator and with lengths from another
iterator.Enums
Functions
Generates random
Vec
s using elements from an iterator.This documentation applies not only to
random_vecs_fixed_length_2_inputs
, but also to
random_vecs_fixed_length_3_inputs
, random_vecs_fixed_length_4_inputs
, and so on.
See random_vecs_fixed_length
for more information.Randomly generates
Vec
s of a given length using elements from a single iterator.Generates random
Vec
s using elements from an iterator and with lengths from another
iterator.This documentation applies not only to
random_vecs_length_2
, but also to
random_vecs_length_3
, random_vecs_length_4
, and so on. See
random_vecs_fixed_length
for more information.Generates random
Vec
s with lengths in $[a, b]$, using elements from an iterator.Generates random
Vec
s with lengths in $[a, b)$, using elements from an iterator.Generates random
Vec
s with a minimum length, using elements from an iterator.