# Implementing a custom Sampler in Distributions.jl

**URL:** https://discourse.julialang.org/t/implementing-a-custom-sampler-in-distributions-jl/41066
**Category:** Statistics
**Tags:** first-steps
**Created:** [June 9, 2020, 1:00pm UTC](https://discourse.julialang.org/t/implementing-a-custom-sampler-in-distributions-jl/41066 "2020-06-09T13:00:40Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [June 9, 2020, 8:25pm UTC](https://discourse.julialang.org/t/implementing-a-custom-sampler-in-distributions-jl/41066/2 "2020-06-09T20:25:16Z")

</div>

I think the documentation is outdated. Most of the distributions in the package implement `rand(rng::AbstractRNG, s::T)` for their type T.

Try implementing only this:

```julia
function Base.rand(rng::AbstractRNG, d::ScaledShiftedBetaSampler)
    sample = rand(rng, d.distribution)
    return sample * (d.b - d.a) + d.a
end

```

I think the rest of the machinery you want will delegate to this method, including methods that use the global rng.

---

_[View the full topic](https://discourse.julialang.org/t/implementing-a-custom-sampler-in-distributions-jl/41066)._
