1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! A list implementation for weighted randomisation.
//!
//! This crate provides the [`WeightedList<V,W>`](WeightedList) struct, which stores values each with assigned weights. When randomly selecting items, those with a higher weight are more likely to be chosen.
//!
//! ## Example
//!
//! ```
//! use weighted_list::*;
//!
//! let wl = WeightedList::<String, u8>::from([
//! (2, "sup".to_string()),
//! (3, "nova".to_string()),
//! (5, "shard".to_string()),
//! ]);
//!
//! for item in &wl {
//! println!("{} has weight {}", item.value, item.weight);
//! }
//!
//! if let Some(result) = wl.select_random_value(&mut rand::rng()) {
//! println!("{result}");
//! }
//! ```
//!
//! ## Why might you need this?
//!
//! - Weighted randomisation for a reward system
//! - Item stacking for an inventory system
//! - Statistical sampling
//!
//! For more detailed guidance on how to use the struct, see [`WeightedList`].
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;