aliasmethod 0.2.0

Implementation of Walker's Alias method.
Documentation

aliasmethod

Build Status

Implementation of Walker's Alias method by Rust.

The algorithm is principally useful when you need to random sampling with replacement by O(1).

Example

use aliasmethod::{new_alias_table, alias_method}

let weights = vec![1.0, 1.0, 8.0];
match new_alias_table(weights) {
    Err(e) => {
        println!(false, "error : {}", e);
    }
    Ok(alias_table) => {
        let n = alias_method().random(&alias_table);
        assert!(0 <= n && n <= weights.length);
}