Crates.io | random_grouping |
lib.rs | random_grouping |
version | 0.3.1 |
source | src |
created_at | 2023-07-05 22:39:20.145138 |
updated_at | 2024-01-14 21:53:07.27952 |
description | Utility for random grouping. |
homepage | |
repository | https://github.com/nossie531/random_grouping |
max_upload_size | |
id | 909438 |
size | 48,708 |
Utility for random grouping.
The author of this crate is not good at English.
Forgive me if the document is hard to read.
This is useful for grouping multiple items into some groups at random.
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)));
}
v0.3.1
v0.3.0
must_use
annotations are added at RandomGrouping
.v0.2.3
v0.2.0
stable
has been changed to true
from false
.divide_by_size
and divide_by_ratio
is changed to
IntoIterator
from slice.divide_slice_by_size
and divide_slice_by_ratio
are introduced
(which are faster for slices).