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.- 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, so it must holdn.NULL(default) uses the default integer type.
Value
(arrayish)
The sampled integers, of shape shape and data type dtype.
Random State
The draws come from the active random state: the global random state (see
nv_set_seed()), or the random state that with_nv_rng_state() or
local_nv_rng_state() make the default for a scope. They advance it in
place.
See also
nv_sample() to sample from an arbitrary population.
Other rng:
local_nv_rng_state(),
nv_normal,
nv_rbinom(),
nv_rng_state(),
nv_sample(),
nv_set_seed(),
nv_uniform
Examples
# roll six dice
with_nv_seed(42L, nv_sample_int(6, 6L))
#> AnvlArray
#> 2
#> 3
#> 6
#> 3
#> 6
#> 6
#> [ CPUi32{6} ]