I know I can pick a random element out of an array with the sample method but this leaves the possibility of an element being picked more than once. I could shuffle the array first and then go from first to last element in order but I understand this is memory intensive and I am looking for a less intensive method if possible!
sample takes an argument:
[*(1..10)].sample(5) #=>[3, 4, 1, 8, 9]
No element will be selected twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With