weighted_random_list

Crates.ioweighted_random_list
lib.rsweighted_random_list
version0.1.1
sourcesrc
created_at2019-04-08 15:10:02.129265
updated_at2019-04-08 15:12:39.209443
descriptionA Vec that allows you to define the weight of each entry and randomly get entries
homepagehttps://gitlab.com/dns2utf8/weighted_random_list
repositoryhttps://gitlab.com/dns2utf8/weighted_random_list
max_upload_size
id126608
size28,499
Stefan Schindler (dns2utf8)

documentation

https://docs.rs/weighted_random_list

README

weighted_random_list

CI Status

A Vec that allows you to define the weight of each entry and randomly get entries:

extern crate weighted_random_list;

use weighted_random_list::WeightedRandomList;

fn main() {
    let list = [
        (1, "https://source.example.net/archive"),
        (10, "https://mirror-slow0.example.net/archive"),
        (10, "https://mirror-slow1.example.net/archive"),
        (100, "https://mirror-fast.example.net/archive"),
    ];

    let mirrors = list.iter()
            .map(|(weight, url)| (*weight, url.to_string()))
            .collect::<WeightedRandomList<String>>();


    let random_choice = mirrors.get_random();
    println!("Using {:?} this time", random_choice);
}
Commit count: 7

cargo fmt