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)
A numeric scalar: the simulated number of successes in size
trials.
Take a look at this function's code in the Stochastic Simulation vignette and see whether you can understand how it works.
link{rbinom}
for the official R function for simulating
from a binomial distribution.
# Simulate one value from a binomial(6, 0.2) distribution.
rbinomial(size = 6, prob = 0.2)
#> [1] 1