generate a random array in ruby

To generate a random array in Ruby, you can use the shuffle method of an array.

main.rb
# Generate a random array of numbers from 1 to 10
arr = (1..10).to_a.shuffle
puts arr.inspect

# Generate a random array of letters
arr = ('A'..'Z').to_a.shuffle
puts arr.inspect
179 chars
8 lines

The shuffle method randomly shuffles the elements in the array, effectively creating a new random order.

gistlibby LogSnag