/n_rands.rb Secret
Last active
February 14, 2021 14:36
Generate array of n random real numbers between 0 and 1 and print the mean value (average) of the values of the array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 1000 | |
a = Array.new(n) { |_| rand } | |
puts a.sum(0.0) / a.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment