jwcooper
(jwcooper)
1
I'm trying to randomize an array, and this is what I have:
arr_set_unordered = randomizer(arr_set)
def randomizer(arr)
result = arr.collect { arr.slice!(rand arr.length) }
end
It does randomize it, but it only returns 3 values instead of the
necessary 5 that are in the arr_set array. Any ideas why?
Thank you!
rab
(Rob Biedenharn)
2
Just to save you a little time:
myarr = [1,2,3,4,5]
=> [1, 2, 3, 4, 5]
myarr.sort_by { rand }
=> [5, 3, 2, 4, 1]
--Jeremy
jwcooper
(jwcooper)
4
Very cool, and very useful information. I appreciate everyones help in
this!
I did a lot of searching on google, but came up empty, so I am thankful
for this help.
My situation isn't extremely time sensitive, but I'm glad to know a
simple solution such as the 3rd, or 4th option will work well.