# Basic question about Distributions, drawing random sample and related documentaion

**URL:** <https://discourse.julialang.org/t/basic-question-about-distributions-drawing-random-sample-and-related-documentaion/33532>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 19, 2020, 12:43am UTC](https://discourse.julialang.org/t/basic-question-about-distributions-drawing-random-sample-and-related-documentaion/33532 "2020-01-19T00:43:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [January 19, 2020, 12:43am UTC](https://discourse.julialang.org/t/basic-question-about-distributions-drawing-random-sample-and-related-documentaion/33532/1 "2020-01-19T00:43:04Z")

</div>

**Julia version**  
`Julia 1.0.5`

**What I want to do:**  
I want to draw a random sample from a continuous uniform distribution, U[10, 50].

**A way to do it in Julia**  
The following works:

```julia
import Distributions

unifdist = Distributions.Uniform(10, 50)

sample_size_1 = Distributions.rand(unifdist)
sample_size_5 = Distributions.rand(unifdist, 5)

```

**Question**  
If I run `methods(Distributions.rand)` 150 methods come up. Searching for Uniform brings up:

`rand(rng::Random.AbstractRNG, d::Distributions.Uniform)`

What I don’t understand is that why the above code example works when I am not passing the first argument. It does not show up as optional in this list of methods. I also searched in the list of methods for the term `UnivariateDistribution`, thinking that UniformDistribution is a subtype of `UnivariateDistribution`. But there is no method that comes up that shows `rng` as optional, or even shows that the number of sampled observations can be entered as an optional argument.

What am I missing? How could I have figured from the documentation (or methods list) that the above code examples are possible?

Thank you. I appreciate your help.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [January 19, 2020, 12:58am UTC](https://discourse.julialang.org/t/basic-question-about-distributions-drawing-random-sample-and-related-documentaion/33532/2 "2020-01-19T00:58:46Z")

</div>

Try @which:

```julia
julia> @which rand(unifdist)
rand(s::Sampleable) in Distributions at C:\Users\...\.julia\packages\Distributions\YLchR\src\genericrand.jl:22

```

This is whats called at first.  
Next step could be `less(raw("C:\Users\...\.julia\packages\Distributions\YLchR\src\genericrand.jl")` or `@less rand(unifdist)`:

`rand(s::Sampleable) = rand(GLOBAL_RNG, s)`

The general help does also tell you that the parameters are optional:

```julia
help?> rand
search: rand randn rand! randn! randexp Random randperm randexp! randperm! randcycle randsubseq randstring randcycle! randsubseq! RandomDevice bitrand

  rand([rng=GLOBAL_RNG], [S], [dims...])

```

[https://docs.julialang.org/en/v1.0/stdlib/InteractiveUtils/](https://docs.julialang.org/en/v1.0/stdlib/InteractiveUtils/)

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [January 19, 2020, 2:40am UTC](https://discourse.julialang.org/t/basic-question-about-distributions-drawing-random-sample-and-related-documentaion/33532/3 "2020-01-19T02:40:11Z")

</div>

@oheil  
Thank you for your response. `@which` helped in understanding why the code works.  
Also, thanks for pointing out InteractiveUtils. That can be quite helpful.
