samedi 25 novembre 2017

Julia: best way to sample from successively shrinking range?

I would like to sample k numbers where the first number is sampled from 1:n and the second from 1:n-1 and the third from 1:n-2 and so on.

I have the below implementation

function shrinksample(n,k)
    [rand(1:n-ki)[1] for ki in 1:k]
end

I wonder what the fastest solution in Julia would be?




Aucun commentaire:

Enregistrer un commentaire