Skip to content

Commit

Permalink
Add rng_gaussian method to the whiskers' context
Browse files Browse the repository at this point in the history
  • Loading branch information
afternoon2 committed Jan 6, 2025
1 parent d3cebbf commit a570ab9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/whiskers/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rand::distributions::uniform::SampleUniform;
use rand::Rng;
use rand_distr::{Distribution, WeightedAliasIndex};
use rand_distr::{Distribution, Normal, WeightedAliasIndex};
use std::{fmt::Debug, ops::Range};
use vsvg::Point;

Expand Down Expand Up @@ -100,6 +100,13 @@ impl<'a> Context<'a> {
Point::new(x, y)
}

/// Helper function to return a number with a Gaussian (normal) distribution
pub fn rng_gaussian(&mut self, mean: f64, std_dev: f64) -> f64 {
let normal = Normal::new(mean, std_dev).expect("Failed to create normal distribution");

normal.sample(&mut self.rng)
}

/// Helper function to display an inspect parameter in the inspect variables UI
pub fn inspect(&mut self, key: impl AsRef<str>, value: impl Debug) {
self.inspect_variables
Expand Down

0 comments on commit a570ab9

Please sign in to comment.