Best way to shuffle elements in a vector of vectors

If vector-of-vectors is the structure you want then you can do this:

julia> using Random

julia> data = [collect(1:5) for i in 1:10];

julia> foreach(shuffle!, data)

julia> data
10-element Array{Array{Int64,1},1}:
 [3, 2, 5, 1, 4]
 [1, 2, 4, 5, 3]
 [2, 3, 1, 5, 4]
 [2, 4, 5, 3, 1]
 [2, 3, 4, 5, 1]
 [3, 1, 4, 5, 2]
 [1, 4, 5, 3, 2]
 [5, 3, 1, 4, 2]
 [4, 5, 3, 2, 1]
 [3, 2, 4, 5, 1]

If you’d prefer to have a matrix with shuffled rows or columns, you can use views:

julia> data = [j for i = 1:10, j = 1:5];

julia> for i = 1:size(data, 1)
           shuffle!(@view data[i,:])
       end

julia> data
10×5 Array{Int64,2}:
 2  5  3  4  1
 4  2  1  5  3
 4  5  3  2  1
 1  4  2  3  5
 5  2  1  3  4
 1  4  3  2  5
 4  3  5  2  1
 2  4  3  5  1
 3  1  2  5  4
 3  1  4  2  5
3 Likes