Arbitrarily sample a Gaussian distribution

Is there an idiomatic way to create a Gaussian distribution whose probability density can then be queried for a known, arbitrary value?

Hoping to take advantage of rand::distributions::Normal, I looked into rand::distributions::Distribution::sample and ::sample_iter, and it looks like both of those methods take an rng argument. However, for my application it would be convenient to be able to pass a float instead.

Yes: Normal distribution - Wikipedia

use statrs::distribution::{Normal, Continuous};

let n = Normal::new(0.0, 1.0).unwrap();
assert_eq!(n.pdf(1.0), 0.2419707245191433497978);

https://docs.rs/statrs/0.15.0/statrs/distribution/struct.Normal.html

I think the rand family of crates is geared towards sampling and doesn't support evaluating PDFs or CDFs of distributions.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.