Crates.io | aliasmethod |
lib.rs | aliasmethod |
version | 0.4.0 |
source | src |
created_at | 2016-08-23 23:55:36.815763 |
updated_at | 2019-08-06 13:18:45.041077 |
description | Implementation of Walker's Alias method. |
homepage | https://github.com/thara/rust_aliasmethod |
repository | https://github.com/thara/rust_aliasmethod |
max_upload_size | |
id | 6088 |
size | 10,476 |
Implementation of Walker's Alias method by Rust.
The algorithm is principally useful when you need to random sampling with replacement by O(1)
.
use rand::XorShiftRng;
use aliasmethod::AliasTable
let weights = vec![1.0, 1.0, 8.0];
let alias_table = AliasTable::new(weights)?;
let rng = XorShiftRng::from_seed([189522394, 1694417663, 1363148323, 4087496301]);
let n = alias_table.random(rng);
assert!(0 <= n && n <= weights.length);