Sampling without replacement

You can use splice! to pick random elements and remove them from the collection:

function sample_wo_repl!(A,n)
    sample = Array{eltype(A)}(n)
    for i in 1:n
        sample[i] = splice!(A, rand(eachindex(A)))
    end
    return sample
end
1 Like