Crate rando [] [src]

A library for iteration in random order.

For some common collection types, this library implements a trait Rando, which provides a method rand_iter that can be called to create a RandIter, an iterator type for iterating over the collection in random order.

Examples

use rand::StdRng;
use rando::Rando;
use rando::assert_eq_up_to_order;

assert_eq_up_to_order(&[1, 2, 3], [1, 2, 3].rand_iter());

assert_eq_up_to_order(&['a', 'b', 'c'], ['c', 'a', 'b'].rand_iter());

let primes = [2, 3, 5, 7, 11];
let mut p2 = Vec::new();

primes.rand_iter().for_each(|n| p2.push(n));

assert_eq_up_to_order(&primes, p2);

// These random number generators have the same seeds...
let rng_1 = StdRng::new()?;
let rng_2 = rng_1.clone();

// ...so `RandIter`s using them should iterate in the same order.
assert_eq!(
    primes.rand_iter().with_rng(rng_1).collect::<Vec<_>>(),
    primes.rand_iter().with_rng(rng_2).collect::<Vec<_>>()
);

Structs

RandIter

An iterator over the items in a collection, in random order.

Constants

DEFAULT_MEM_LEN

By default, a RandIter will be able to iterate over this number of items without allocating memory on the heap.

Traits

Memory

A trait for data-structures in which a RandIter can store values of type K representing the indices or other keys of the items that it has already yielded.

Rando

A trait for collections over which this library allows one to iterate in random order.

Functions

assert_eq_up_to_order

Asserts that the two given iterators (or values that can be converted into iterators) yield the same items, without regard to the order in which those items are yielded.