outer_vec

Function outer_vec 

Source
pub fn outer_vec<T>(
    elem_die: impl Die<T>,
    length_range: impl LengthRange,
) -> impl Die<Vec<T>>
Expand description

Similar to dice::vec but each element is generated using only a random part of Limit.

If you want to generate a Vec that contains other collections, then you should consider using this generator for the outer Vec. That way the overall length is bounded by [Limit] (and not the square of [Limit)].

§Panics

Panics if the range is empty.

§Examples

use dicetest::prelude::*;
use dicetest::{Prng, Limit};

let mut prng = Prng::from_seed(0x5EED.into());
let limit = Limit::default();
let mut fate = Fate::new(&mut prng, limit);

let elem_die = dice::u8(..);
let vec_die = dice::vec(elem_die, ..);
let vec_of_vecs_die = dice::outer_vec(vec_die, ..);

let vec_of_vecs = fate.roll(vec_of_vecs_die);
assert!(vec_of_vecs.iter().flatten().count() <= 100);