1mod context_ext;
2mod macros;
3mod sampling_algorithms;
4
5use std::any::{Any, TypeId};
6use std::cell::RefCell;
7
8pub use context_ext::ContextRandomExt;
9pub use macros::define_rng;
10pub use sampling_algorithms::{
11 sample_multiple_from_known_length, sample_multiple_l_reservoir,
12 sample_single_from_known_length, sample_single_l_reservoir,
13};
14
15use crate::rand::SeedableRng;
16use crate::{define_data_plugin, HashMap, HashMapExt};
17
18pub trait RngId: Copy + Clone {
19 type RngType: SeedableRng;
20 fn get_name() -> &'static str;
21}
22
23struct RngHolder {
26 rng: Box<dyn Any>,
27}
28
29struct RngData {
30 base_seed: u64,
31 rng_holders: RefCell<HashMap<TypeId, RngHolder>>,
32}
33
34define_data_plugin!(
40 RngPlugin,
41 RngData,
42 RngData {
43 base_seed: 0,
44 rng_holders: RefCell::new(HashMap::new()),
45 }
46);