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, initial_state, size = 1L, prob = 0.5, dtype = NULL)

Arguments

shape

(integer())
Shape of the result.

initial_state

(arrayish)
RNG state: a 1-D array of two ui64 elements, as nv_rng_state() returns. The data type and length are fixed by the generator, not by the default data types, and the returned state has 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.

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} ]