Samples from a binomial distribution with \(n\) trials and success probability \(p\).
When size = 1 (the default), this is a Bernoulli distribution.
Arguments
- shape
(
integer())
Shape of the result.- initial_state
(
arrayish)
RNG state: a 1-D array of twoui64elements, asnv_rng_state()returns. The data type and length are fixed by the generator, not by the default data types, and the returnedstatehas them too.- size
(
integer(1))
Number of trials.- prob
(
numeric(1))
Probability of success on each trial.- dtype
(
NULL|character(1)|DataType)
Numeric type of the sample.NULL(default) uses the default integer type. The number of successes are converted to it.
Value
(named list of two arrayish)
Elements state, the updated RNG state, and values, the sample of shape
shape and data type dtype.
See also
Other rng:
nv_normal,
nv_rng_state(),
nv_runif(),
nv_sample(),
nv_sample_int()
Examples
# Bernoulli samples; `state` is the updated RNG state
state <- nv_rng_state(42L)
result <- nv_rbinom(c(2, 3), state)
result$values
#> AnvlArray
#> 0 1 1
#> 0 0 1
#> [ CPUi32{2,3} ]