[][src]Module hidden::dispenser

An emitter of choices that shuffles its order internally afterwards.

The recommended way of using this module is with it's Dispenser struct:

use hidden::dispenser::Dispenser;

let elements = vec!['a', 'b', 'c', 'd', 'e', 'f'];
let mut dispenser = Dispenser::new(elements.len());

let za_hando = dispenser.make_hand(&elements).expect("created with the same elements slice");
let star_finger = dispenser.make_hand(&elements).expect("created with the same elements slice");

let hando_choice = za_hando.choose(1).unwrap();
let star_choice = star_finger.choose(1).unwrap();

// At this point, it's possible that hando_choice and star_choice are or aren't the same,
// by design of random shuffling.

// However, choosing from the same index, per hand, *is* guaranteed to be the same.
assert_eq!(hando_choice, za_hando.choose(1).unwrap());
assert_eq!(star_choice, star_finger.choose(1).unwrap());

Upon every call to make_hand, and upon creation, the dispenser shuffles it's internal state, so that it becomes an internal state it may "dispense", and then change, which stays that way until the next "dispensing".

Structs

Dispenser

A struct that holds a hidden variable, dispenses Hands with a lock on a state, and shuffles afterward.

Hand

A lock on a slice of choices, with a slice of elements to match them.