Basic question about Distributions, drawing random sample and related documentaion

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:

import Distributions

unifdist = Distributions.Uniform(10, 50)

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

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.

Try @which:

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:

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...])

1 Like

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