Skip to contents

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

To sample from a population other than 1:n, use nv_sample().

Usage

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

Arguments

shape

(integer())
Shape.

initial_state

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

n

(integer(1))
Size of the population, i.e. the integers 1 to n are sampled.

dtype

(character(1) | DataType)
Data type of the sampled integers.

Value

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

See also

nv_sample() to sample from an arbitrary population.

Other rng: nv_normal, nv_rbinom(), nv_rng_state(), nv_runif(), nv_sample()

Examples

state <- nv_rng_state(42L)
# Roll 6 dice
result <- nv_sample_int(6, state, 6L)
result[[2]]
#> AnvlArray
#>  4
#>  6
#>  2
#>  5
#>  1
#>  2
#> [ CPUi32{6} ]