To generate a random number from a normal distribution with a mean of 0 and a standard deviation of 1 in Ruby, we can use the rand
method from the Distribution
module of the ruby-statistics
gem. Here's how:
main.rb193 chars8 lines
In this code, we first require the statistics2
gem. We then use the rnorm
method to generate a random number from a normal distribution with mean 0 and standard deviation 1. We pass the mean and standard deviation as the first and second argument respectively.
The rnorm
method returns a single random number.
We then print the result using the puts
method.
gistlibby LogSnag