udp bench: use gamma distribution for torrent selection

This commit is contained in:
Joakim Frostegård 2022-10-26 20:03:59 +02:00
parent db561a1101
commit 84f420e2c5
3 changed files with 12 additions and 10 deletions

View file

@ -1,8 +1,10 @@
use indicatif::{ProgressBar, ProgressStyle};
use rand::Rng;
use rand_distr::Pareto;
use rand_distr::Gamma;
pub const GAMMA_SHAPE: f64 = 0.2;
pub const GAMMA_SCALE: f64 = 100.0;
pub const PARETO_SHAPE: f64 = 0.1;
pub const NUM_INFO_HASHES: usize = 10_000;
pub fn create_progress_bar(name: &str, iterations: u64) -> ProgressBar {
@ -12,8 +14,8 @@ pub fn create_progress_bar(name: &str, iterations: u64) -> ProgressBar {
ProgressBar::new(iterations).with_style(style)
}
pub fn pareto_usize(rng: &mut impl Rng, pareto: Pareto<f64>, max: usize) -> usize {
let p: f64 = rng.sample(pareto);
pub fn gamma_usize(rng: &mut impl Rng, gamma: Gamma<f64>, max: usize) -> usize {
let p: f64 = rng.sample(gamma);
let p = (p.min(101.0f64) - 1.0) / 100.0;
(p * max as f64) as usize