Question: In Ruby. Task: Write a program that generates 100 random numbers between 1 and 1000. Then, the program should calculate the sum, average, standard deviation,

In Ruby.

Task: Write a program that generates 100 random numbers between 1 and 1000. Then, the program should calculate the sum, average, standard deviation, minimum, and maximum of all the numbers and output them.

Discussion: Random numbers are often useful in computer programming. In Ruby, if you want to generate a random number, you can use the rand command: randNum = rand # => random number between 0.0 and 1.0 In order to force a random number to be in a certain range, you can pass some parameters along with arithmetic to the rand command. For example, if you want to generate a random number between 1 and 1000 (inclusive), you would type: randNum = 1 + rand(1000) Your program should generate 100 random numbers in the range 1 to 1000 and store them in an array. Then, your program should calculate the sum, average, standard deviation, minimum, and maximum of all the numbers. Calculating the sum, average, minimum, and maximum are all fairly straight-forward. The only one that might be a little tricky is the standard deviation. You can use this formula to calculate the standard deviation: One further requirement: you must store the sum, average, standard deviation, minimum and maximum in a hash called \stats". In other words, at the end of your program, you should have a hash variable that looks like this: stats = {:sum => 123, :avg => 456, :std_dev => 789, :min => 3, :max => 998} Then, you must iterate over that hash in order to output all the values accordingly.

Your program should run like this:

Generating 100 random numbers...

Here are the results:

sum: 247563

average: 672

standard deviation: 39

minimum: 2

maximum: 974

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!