To get a random number from a normal distribution with a mean of 0 and a standard deviation of 1 in rust, you can use the rand crate. Here's an example code snippet that shows how to generate a random number from a standard normal distribution:
main.rs291 chars15 lines
The Normal::new(mean, std_dev)
creates a normal distribution object with the specified mean and standard deviation. The rng
variable is a random number generator provided by the rand crate. Finally, the sample
method is used on the normal distribution object to generate a random number from that distribution.
The above code will print a random number from the standard normal distribution to the console. You can modify the mean
and std_dev
variables as desired to generate random numbers from other normal distributions.
gistlibby LogSnag