Skip to contents

Samples integers from 1 to n with equal probability (with replacement), analogous to R's sample.int(n, size, replace = TRUE).

Usage

nv_rdunif(shape, initial_state, n, dtype = "i32")

Arguments

shape

(integer())
Shape.

initial_state

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

n

(integer(1))
Number of categories (samples integers 1 to n).

dtype

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

Value

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

Examples

jit_eval({
  state <- nv_rng_state(42L)
  # Roll 6 dice
  result <- nv_rdunif(6, state, n = 6L)
  result[[2]]
})
#> AnvilTensor
#>  3
#>  5
#>  1
#>  4
#>  1
#>  1
#> [ CPUi32{6} ]