weighted_random_list 0.1.1

A Vec<T> that allows you to define the weight of each entry and randomly get entries
Documentation
  • Coverage
  • 52.94%
    9 out of 17 items documented6 out of 10 items with examples
  • Size
  • Source code size: 32.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.13 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • dns2utf8/weighted_random_list
    0 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dns2utf8

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);
}