Generating different combinations of random numbers

Stacker-flow

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----"
Thiago Lewin

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Generating a set of random numbers that form sum under two combinations

From Dev

Generating 2 Random Numbers that are Different C#

From Dev

Generating small range of different random numbers?

From Dev

Generating two identical random numbers and one that is different

From Java

Generating random numbers with Swift

From Dev

Generating random numbers in Haskell

From Dev

Generating unique random numbers

From Dev

Generating weighted random numbers

From Dev

Generating random poll numbers

From Dev

Generating groups of random numbers

From Dev

Generating unique random numbers

From Dev

Generating a set of random numbers

From Dev

Generating sequence of random numbers

From Dev

Generating random numbers randomly

From Dev

Generating random numbers on different input texts and ensuring random numbers shown are unique

From Dev

Generating a high number of unique random combinations

From Dev

Generating random numbers in a particular range

From Dev

Generating random numbers of exponential distribution

From Dev

Random generating numbers on a given ratio

From Dev

Generating Random Numbers for RPG games

From Dev

Generating random numbers without repeats

From Dev

Generating uniform random numbers in Lua

From Dev

generating random numbers in a Fortran Module

From Dev

Generating secure random numbers in Rust

From Dev

generating unique random numbers in Julia

From Dev

Generating random numbers in a specific interval

From Dev

Java Generating random numbers in a for loop

From Dev

Generating uniform random numbers in Lua

From Dev

Random generating numbers on a given ratio