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, n, dtype = NULL)

Arguments

shape

(integer())
Shape of the result.

n

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

dtype

(NULL | character(1) | DataType)
Numeric type of the sampled integers. The sampled values are converted to it, so it must hold n. 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

Examples

# roll six dice
with_nv_seed(42L, nv_sample_int(6, 6L))
#> AnvlArray
#>  2
#>  3
#>  6
#>  3
#>  6
#>  6
#> [ CPUi32{6} ]