Search⌘ K

Generate Lotto Numbers

Explore how to generate six unique lotto numbers between 1 and 49 using Ruby programming. Understand how to use random number generation, check for existing elements in an array, and control iteration flow with the next keyword. This lesson helps you develop problem-solving skills by creating a practical utility that ensures number uniqueness through iteration and condition checks.

We'll cover the following...

Problem

Write a program to generate six lotto numbers. Lotto numbers are between 1–49.

Your winning lotto numbers are [23, 34, 12, 6, 7, 49], good luck!
Generating six lotto numbers

Purpose

  • Check whether an array contains an element

  • Use a random number generator

  • Use the next keyword

Analyze

We need the lotto numbers to be randomly generated, and they have to be unique. We can use ...