# What is rand(distrSamp, n) for distrSamp being a probability distribution sampler?

**URL:** <https://discourse.julialang.org/t/what-is-rand-distrsamp-n-for-distrsamp-being-a-probability-distribution-sampler/20027>\
**Category:** General Usage\
**Created:** [January 24, 2019, 10:04am UTC](https://discourse.julialang.org/t/what-is-rand-distrsamp-n-for-distrsamp-being-a-probability-distribution-sampler/20027 "2019-01-24T10:04:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [January 24, 2019, 10:04am UTC](https://discourse.julialang.org/t/what-is-rand-distrsamp-n-for-distrsamp-being-a-probability-distribution-sampler/20027/1 "2019-01-24T10:04:57Z")

</div>

In the Distribution package, suppose `distrSamp` is of type probability distribution sampler. What exactly does the function`rand(distrSamp,n)` do ? What’s the returned value of this function? Or is it because of method dispatching, different probability distribution sampler would make this function return different values?

`Edit:` I think I figure it out. I think it’s because of both “method dispatching” and the property of each probability distribution sampler. For example,

If `distrSamp` is `Categorical([0.5, 0.2, 0.3])`, then `rand(distrSamp,100)` would return a vector of length 100, with each element of this vector being picked from 1 (with probability 0.5), 2 (with probability 0.2) and 3 (with probability 0.3).

On the other hand, if `distrSamp` is `Exponential(0.02)`, then `rand(distrSamp,100)` would return a vector of length 100, with all of them together form a part / sample of an exponential distribution with rate 0.02. Or do you have a better explanation for Exponential distribution this case?
