R/get_seed.R

Defines functions get_seed

Documented in get_seed

#' @title Get the Random Seed
#'
#' @description
#' Retrieves the current random seed (`.Random.seed` in the global environment),
#' and initializes the RNG first, if necessary.
#'
#' @return `integer()`. Depends on the [base::RNGkind()].
#' @export
#' @examples
#' str(get_seed())
get_seed = function() {
  seed = get0(".Random.seed", globalenv(), mode = "integer", inherits = FALSE)
  if (is.null(seed)) {
    runif(1L)
    seed = get0(".Random.seed", globalenv(), mode = "integer", inherits = FALSE)
  }
  return(seed)
}

Try the mlr3misc package in your browser

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

mlr3misc documentation built on April 4, 2025, 1:51 a.m.