Discrete Random Variables

Bernoulli

RandomVariates.bernoulli_rngFunction
bernoulli_rng(p, shape=1; seed=nothing)

Generate a shape element array of random variables from a Bernoulli(p) distribution. Optionally you can set a specific seed.

Notes

The pdf of the Bernoulli Distribution is given:

$f(x, p) = p^x (1-p)^{1-x} \quad x \in [0,1]$

Examples

julia> bernoulli_rng(.34)
1-element BitVector:
 0

julia> bernoulli_rng(.34, 5)
5-element BitVector:
 0
 0
 1
 0
 1

julia> bernoulli_rng(.8, (2,2), seed=42)
2×2 BitMatrix:
 1  0
 0  1

References

D.P. Kroese, T. Taimre, Z.I. Botev. Handbook of Monte Carlo Methods. Wiley Series in Probability and Statistics, John Wiley & Sons, New York, 2011.

source

Binomial

RandomVariates.binomial_rngFunction
binomial_rng(p, n, shape=1; seed=nothing)

Generate a shape element array of random variables from a Binomial(p, n) distribution. Optionally you can set a specific seed.

Notes

The Binomial(x, n, p) distribution describes the total number of successes in a sequence of n Bernoulli(p) trials.

The pdf is given:

$f(x,n,p) = \binom{n}{x} p^x (1-p)^{n-x} \quad x = 0,1,\dots, n$

Examples

julia> binomial_rng(.3, 10)
1×1 Matrix{Int64}:
 3

julia> binomial_rng(.3, 10, (2,2))
2×2×1 Array{Int64, 3}:
[:, :, 1] =
 2  1
 2  2

References

D.P. Kroese, T. Taimre, Z.I. Botev. Handbook of Monte Carlo Methods. Wiley Series in Probability and Statistics, John Wiley & Sons, New York, 2011.

source

Geometric

RandomVariates.geometric_rngFunction
geometric_rng(p, shape=1; seed=nothing)

Generate a shape element array of random variables from a Geometric(p) distribution. Optionally you can set a specific seed.

Notes

The Geometric distribution is given:

$f(x,p) = (1-p)^{x-1}p) \quad x = 1,2,3,…$

where $0 ≤ p ≤ 1$

Examples

julia> geometric_rng(.8)
1-element Vector{Int64}:
 1

julia> geometric_rng(.8, 5)
5-element Vector{Int64}:
 2
 3
 1
 1
 1

julia> geometric_rng(.8, (2,2), seed=45)
2×2 Matrix{Int64}:
 1  1
 1  1
 

References

D.P. Kroese, T. Taimre, Z.I. Botev. Handbook of Monte Carlo Methods. Wiley Series in Probability and Statistics, John Wiley & Sons, New York, 2011.

C. Alexopoulos, D. Goldsman. Random variate generation. 2020.

source

Poisson

RandomVariates.poisson_rngFunction
poisson_rng(p, n, shape=1; seed=nothing)

Generate a shape element array of random variables from a Poisson(λ) distribution. Optionally you can set a specific seed.

Notes

The Poisson distribution is given by:

$f(x, λ) = \frac{λ^x}{x!} e^λ \quad x = 0,1,2,…$

Examples

julia> poisson_rng(3)
1×1 Matrix{Int64}:
 7

julia> poisson_rng(10, 5)
5×1 Matrix{Int64}:
 13
 11
 10
  8
 15

julia> poisson_rng(10, (5,5))
5×5×1 Array{Int64, 3}:
[:, :, 1] =
 11  15   9  11   9
  8  15  13  10   9
 11  12   4  10   6
  7   9  13  11   7
 13   7  10  10  14
 

References

R. Larson, A. Odoni. Urban operations research. Prentice-Hall, New Jersey, 1981.

G. Last, M. Penrose. Lectures on the poisson process. Cambridge University Press, 2017.

source

Negative Binomial

RandomVariates.neg_binomial_rngFunction
neg_binomial_rng(p, r, shape=1; seed=nothing)

Generate a shape element array of random variables from a Negative Binomial(p, r) distribution. Optionally you can set a specific seed.

Notes

The Negative Binomial distribution is given:

$f(x,p,r) = \binom{x-1}{r-1} (1-p)^{x-r} p^r \quad x = 0,1,\dots, n$

Examples

julia> neg_binomial_rng(.5, 2)
1-element Vector{Float64}:
 3.0

julia> neg_binomial_rng(.5, 5, 5)
5-element Vector{Float64}:
  8.0
 10.0
  8.0
 13.0
 10.0

julia> neg_binomial_rng(.5, 2, (2,2))
2×2 Matrix{Float64}:
 3.0  4.0
 4.0  2.0
 

References

Walk, C. Handbook on statistical distributions for experimentalists. 2007.

source
RandomVariates.conv_neg_binomial_rngFunction
conv_neg_binomial_rng(p, r, shape=1; seed=nothing)

Generate a shape element array of random variables from a Negative Binomial(p, r) distribution. Optionally you can set a specific seed.

Notes

The Negative Binomial distribution is given:

$f(x,p,r) = \binom{x-1}{r-1} (1-p)^{x-r} p^r \quad x = 0,1,\dots, n$

Uses a convolution algorithm to generate random variables, which is slightly slower than neg_binomial_rng.

Examples

julia> conv_neg_binomial_rng(.4, 5, 1)
1×1 Matrix{Int64}:
 8

julia> conv_neg_binomial_rng(.4, 5, 5)
5×1 Matrix{Int64}:
 11
 14 
 8
 10
 13

julia> conv_neg_binomial_rng(.4, 5, (2,2))
2×2×1 Array{Int64, 3}:
[:, :, 1] =
 20  11
 7  10

References

Law, A. Simulation modeling and analysis, 5th Ed. McGraw Hill Education, Tuscon, 2013.

source