Skip to contents

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

Usage

nv_rbinom(shape, initial_state, n = 1L, prob = 0.5, dtype = "i32")

Arguments

shape

(integer())
Shape.

initial_state

(tensorish)
RNG state (ui64[2]).

n

(integer(1))
Number of trials.

prob

(numeric(1))
Probability of success on each trial.

dtype

(character(1) | stablehlo::TensorDataType)
Data type.

Value

(list() of tensorish)
List of two elements: the updated RNG state and the sampled values.

Examples

jit_eval({
  state <- nv_rng_state(42L)
  # Bernoulli samples
  result <- nv_rbinom(c(2, 3), state)
  result[[2]]
})
#> AnvilTensor
#>  0 0 1
#>  0 1 1
#> [ CPUi32{2,3} ]