# Sampling without replacement

**URL:** <https://discourse.julialang.org/t/sampling-without-replacement/1073>\
**Category:** Statistics\
**Tags:** statistics\
**Created:** [December 20, 2016, 9:22pm UTC](https://discourse.julialang.org/t/sampling-without-replacement/1073 "2016-12-20T21:22:56Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![shorty66](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shorty66/32/3254_2.png) [@shorty66](https://discourse.julialang.org/u/shorty66)\
**Post date:** [September 19, 2017, 7:39am UTC](https://discourse.julialang.org/t/sampling-without-replacement/1073/5 "2017-09-19T07:39:36Z")

</div>

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

```julia
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

```

---

_[View the full topic](https://discourse.julialang.org/t/sampling-without-replacement/1073)._
