...
/Solution: Generating Lotto Numbers Using a Method
Solution: Generating Lotto Numbers Using a Method
Take a look at the solution to the problem from the previous lesson and see the method call in action.
We'll cover the following...
Solution
Press + to interact
def get_next_valid_lotto_number(existing_lotto_numbers)new_lotto_number = rand(49)while existing_lotto_numbers.include?(new_lotto_number)new_lotto_number = rand(49)endreturn new_lotto_numberendlotto_numbers = []6.times donew_valid_number = get_next_valid_lotto_number(lotto_numbers)lotto_numbers << new_valid_numberendputs "Your winning lotto numbers are #{lotto_numbers.inspect}, good luck!"
Explanation
Line 2: We generates a ...