I want to generate n unique elements from a list of numbers. I came across this answer but that only gives me one element. I want n distinct elements from the list.
How do I go about doing this?
I have tried using rand(list,n)
but this sometimes gives me repeated elements from list
so that doesn't work.
Try Distributions.sample
StatsBase.sample
:
jl> using StatsBase: sample
jl> x = rand(10);
jl> sample(x, 3; replace=false)
3-element Vector{Float64}:
0.6816165016249632
0.8500982926818003
0.6518188633423712
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With