While trying to experiment with Ruby and see what it can do, I put together this program to generate fake lottery numbers.
I am trying to generate all the combinations possible but it doesn't seem to work, can you see where I am going wrong?
lotto = [rand(1...50), rand(1...50), rand(1...50), rand(1...50), rand(1...50), rand(1...50)].uniq
lotto_results = lotto.combination(6).cycle.to_a
puts "----START----"
count = 0
lotto_results.each do |x|
count += 1
puts "Comination #{count}: #{x}"
puts "-------------"
end
puts "----FINISH----"
If you want to print all possible combinations, just do the follow:
(1..50).to_a.combination(6).each_with_index do |c, idx|
puts "combination #{idx}: #{c}"
end
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments