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)
}
mlr-org/mlr3misc documentation built on April 28, 2024, 11 p.m.