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().
Arguments
- shape
(
integer())
Shape of the result.- initial_state
(
arrayish)
RNG state: a 1-D array of twoui64elements, asnv_rng_state()returns. The data type and length are fixed by the generator, not by the default data types, and the returnedstatehas them too.- n
(
integer(1))
Size of the population, i.e. the integers1tonare sampled.- dtype
(
NULL|character(1)|DataType)
Numeric type of the sampled integers. The sampled values are converted to it.NULL(default) uses the default integer type.
Value
(named list of two arrayish)
Elements state, the updated RNG state, and values, the sampled integers
of shape shape and data type dtype.
See also
nv_sample() to sample from an arbitrary population.
Other rng:
nv_normal,
nv_rbinom(),
nv_rng_state(),
nv_runif(),
nv_sample()
Examples
# roll six dice; `state` is the updated RNG state
state <- nv_rng_state(42L)
result <- nv_sample_int(6, state, 6L)
result$values
#> AnvlArray
#> 4
#> 6
#> 2
#> 5
#> 1
#> 2
#> [ CPUi32{6} ]