8 releases

0.2.1 Dec 4, 2025
0.2.0 Dec 4, 2025
0.1.7 Sep 30, 2021
0.1.3 Oct 2, 2019

#798 in Algorithms

Download history 329/week @ 2025-12-25 203/week @ 2026-01-01 193/week @ 2026-01-08 205/week @ 2026-01-15 211/week @ 2026-01-22 268/week @ 2026-01-29 249/week @ 2026-02-05 215/week @ 2026-02-12 239/week @ 2026-02-19 237/week @ 2026-02-26 318/week @ 2026-03-05 323/week @ 2026-03-12 241/week @ 2026-03-19 225/week @ 2026-03-26 866/week @ 2026-04-02 843/week @ 2026-04-09

2,227 downloads per month
Used in 10 crates (6 directly)

MIT license

15KB
264 lines

Crate implementing various kinds of shuffling algorithms such as Inverse Riffle Shuffle (more algorithms coming soon).

Why

This crate aims to provide good abstractions to shuffle collections when all you have is just a source of randomness. (but we also implement Fisher-Yates, because why not?)

Assuming that the source of the randomness is good, all of the shuffling algorithms return a permutation from a uniform distribution.

Example




use shuffle::shuffler::Shuffler;
use shuffle::irs::Irs;
use rand::rngs::mock::StepRng;

let mut rng = StepRng::new(2, 13);
let mut irs = Irs::default();

let mut input = vec![1, 2, 3, 4, 5];

irs.shuffle(&mut input, &mut rng);
assert_eq!(&input, &[4, 1, 5, 3, 2]);

shuffle

Various shuffling algorithms for rust.

Currently implemented shuffling algorithms

  • Inverse Riffle Shuffle
  • Fisher-Yates
  • ... ? TODO

no_std Support

This crate is no_std compatible but requires the alloc crate (for Vec).

Examples

use shuffle::shuffler::Shuffler;
use shuffle::irs::Irs;
use rand::rngs::mock::StepRng;

let mut rng = StepRng::new(2, 13);
let mut irs = Irs::default();
let mut input = vec![1, 2, 3, 4, 5];

irs.shuffle(&mut input, &mut rng);
assert_eq!(&input, &[4, 1, 5, 3, 2]);

Dependencies

~1.5MB
~29K SLoC