use rand::Rng;
#[derive(Clone, Copy)]
pub enum RolloutDecision {
UseControl,
UseExperimentalAndCompare,
UseExperimental,
}
pub trait RolloutStrategy {
fn rollout_decision(&self) -> RolloutDecision;
}
impl RolloutStrategy for RolloutDecision {
fn rollout_decision(&self) -> RolloutDecision {
*self
}
}
pub struct Percent(f64);
impl Percent {
pub fn new(percent: f64) -> Self {
Self(percent / 100.0)
}
}
impl RolloutStrategy for Percent {
fn rollout_decision(&self) -> RolloutDecision {
let mut rng = rand::thread_rng();
if rng.gen::<f64>() < self.0 {
RolloutDecision::UseExperimentalAndCompare
} else {
RolloutDecision::UseControl
}
}
}