R/rng-utils.R

Defines functions .r4vn_set_seed_if .r4vn_seed_normalize

# R4VN random-number helpers -------------------------------------------------
# CRAN-friendly policy: public functions default to seed = NULL. A seed is
# applied only when a user explicitly supplies one.

.r4vn_seed_normalize <- function(seed) {
  if (is.null(seed)) return(NA_integer_)
  if (!is.numeric(seed) || length(seed) != 1L || !is.finite(seed)) {
    stop("`seed` must be NULL or one finite numeric value.", call. = FALSE)
  }
  as.integer(abs(seed) %% .Machine$integer.max)
}

.r4vn_set_seed_if <- function(seed) {
  if (is.null(seed) || !length(seed) || is.na(seed)) return(invisible(FALSE))
  if (!is.numeric(seed) || length(seed) != 1L || !is.finite(seed)) {
    stop("`seed` must be NULL or one finite numeric value.", call. = FALSE)
  }
  set.seed(as.integer(seed))
  invisible(TRUE)
}

Try the R4VN package in your browser

Any scripts or data that you put into this service are public.

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.