Simulates one value from a binomial distribution with parameters size (the number of independent Bernoulli trials) and prob (the probability of success on any given trial).

rbinomial(size, prob)

Arguments

size

An integer scalar. The number of trials.

prob

A numeric scalar. The probability of success on each trial.

Value

A numeric scalar: the simulated number of successes in size

trials.

Details

Take a look at this function's code in the Stochastic Simulation vignette and see whether you can understand how it works.

See also

link{rbinom} for the official R function for simulating from a binomial distribution.

Examples

# Simulate one value from a binomial(6, 0.2) distribution.
rbinomial(size = 6, prob = 0.2)
#> [1] 1