Freelancer Friday

Ruby Coding Exercise: How to Generate an Array of Random Numbers in Ruby

In this coding exercise I walk through a TDD process for implementing an Array generator that contains random numbers in a specific range.


Generate an array of 20 random integers, with the integer values ranging from 1 to 1000.

Exercise File

Code File

Exercise Description

Write a program that automatically generates an array containing 20 random integers, ranging from 1 to 1000.

Sample Output

=> [695, 627, 849, 315, 203, 520, 433, 837, 923, 796, 6, 472, 964, 717, 549, 963, 787, 20, 589, 628]

Real World Usage

Being able to generate a set of random numbers is common in a number of different scenarios, including:

  • Game development
  • Creating test data
  • Algorithm implementations


Can be found on the solutions branch on github.

Jordan Hudgens
the authorJordan Hudgens

Leave a Reply