3 unstable releases

Uses old Rust 2015

0.2.0 May 25, 2018
0.1.1 Jan 14, 2018
0.1.0 Jan 12, 2018

#20 in #iter


Used in irc-bot

Apache-2.0

16KB
297 lines

rando

A Rust library for iteration in random order.

See the documentation on Docs.rs.

This software is licensed under the Apache License, version 2.0.

Building

Most users should use Rust's build tool Cargo to build this software:

$ cargo build
$ cargo check
$ cargo test
$ # Etc.

Users of the Linux distribution NixOS may prefer to use the provided Makefile, which wraps the tool nix-shell:

$ make build
$ make check
$ make test
$ # Etc.

lib.rs:

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

# extern crate rand;
# extern crate rando;
use rand::EntropyRng;
use rand::SeedableRng;
use rand::StdRng;
use rando::Rando;
use rando::assert_eq_up_to_order;
# fn main() {
# (|| -> ::std::io::Result<()> {

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::from_rng(EntropyRng::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<_>>()
);
# Ok(())
# })().unwrap()
# }

Dependencies

~530KB

[