Skip to contents

Samples from a binomial distribution with \(n\) trials and success probability \(p\). When size = 1 (the default), this is a Bernoulli distribution.

Usage

nv_rbinom(shape, size = 1L, prob = 0.5, dtype = NULL)

Arguments

shape

(integer())
Shape of the result.

size

(integer(1))
Number of trials. 0 gives a sample of zeros, like rbinom().

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, so it must hold size.

Value

(arrayish)
The sample, of shape shape and data type dtype.

Random State

The draws come from the active random state: the global random state (see nv_set_seed()), or the random state that with_nv_rng_state() or local_nv_rng_state() make the default for a scope. They advance it in place.

Examples

# Bernoulli samples
with_nv_seed(42L, nv_rbinom(c(2, 3)))
#> AnvlArray
#>  1 0 0
#>  1 1 0
#> [ CPUi32{2,3} ]