9 releases
Uses new Rust 2024
0.4.1 | Jun 22, 2025 |
---|---|
0.4.0 | Jun 22, 2025 |
0.3.1 | Jan 14, 2024 |
0.3.0 | Oct 30, 2023 |
0.1.0 | Jul 5, 2023 |
#587 in Algorithms
205 downloads per month
18KB
284 lines
random_grouping
Utility for random grouping.
The author of this crate is not good at English.
Forgive me if the document is hard to read.
What is this?
This is useful for grouping multiple items into some groups at random.
Examples
let mut rg = RandomGrouping::new();
let samples = (0..10).collect::<Vec<_>>();
let ratios = [0.3, 0.3, 0.2];
let result = rg.divide_by_ratio(&samples, &ratios);
assert!(result.len() == ratios.len());
for i in 0..result.len() {
let group_size = (ratios[i] * samples.len() as f64).floor() as usize;
assert!(result[i].len() == group_size);
assert!(result[i].iter().all(|x| samples.contains(x)));
}
What's New
v0.4.1
- Minor refactoring.
v0.4.0
- Rust edition is updated to 2024.
- Add
prelude
module (Although this crate is very small). - Polish documentations.
v0.3.1
- Minor refactoring.
v0.3.0
must_use
annotations are added atRandomGrouping
.
v0.2.3
- Bug fix: Remove unwanted Debug output.
v0.2.0
- The default value of
stable
has been changed totrue
fromfalse
. - The first argument of
divide_by_size
anddivide_by_ratio
is changed toIntoIterator
from slice. - Instead,
divide_slice_by_size
anddivide_slice_by_ratio
are introduced (which are faster for slices).
Dependencies
~440KB