Is there an easy way to zip 2 arrays in random locations and keep their original order?
for example
a=[0,1,2,3,4,5,6,7,8,9,10]
b=["one","two","three","four"]
and a random number from 0 to 5 with rand(5)
zipped = [0,"one",1,2,3,"two",4,"three",5,6,7,8,"four",9,10]
and the random series would be 1,3,1,4 as location to where to “zip” each element of b into a
The best I could do is
i=0
merged=a
b.each do |x|
rnd = rand(5)
merged.insert(i+rnd,x)
i=i+rnd
end
This version will give a balanced shuffling, with insertions not biased to either end of the array.