File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1
1
use rand:: distributions:: uniform:: SampleUniform ;
2
2
use rand:: Rng ;
3
- use rand_distr:: { Distribution , WeightedAliasIndex } ;
3
+ use rand_distr:: { Distribution , Normal , WeightedAliasIndex } ;
4
4
use std:: { fmt:: Debug , ops:: Range } ;
5
5
use vsvg:: Point ;
6
6
@@ -100,6 +100,17 @@ impl<'a> Context<'a> {
100
100
Point :: new ( x, y)
101
101
}
102
102
103
+ /// Helper function to return a number with a Gaussian (normal) distribution
104
+ ///
105
+ /// # Panics
106
+ ///
107
+ /// Panics when the `rand_distr` can't create a Normal distribution struct instance.
108
+ pub fn rng_gaussian ( & mut self , mean : f64 , std_dev : f64 ) -> f64 {
109
+ let normal = Normal :: new ( mean, std_dev) . expect ( "Failed to create normal distribution" ) ;
110
+
111
+ normal. sample ( & mut self . rng )
112
+ }
113
+
103
114
/// Helper function to display an inspect parameter in the inspect variables UI
104
115
pub fn inspect ( & mut self , key : impl AsRef < str > , value : impl Debug ) {
105
116
self . inspect_variables
You can’t perform that action at this time.
0 commit comments