Questions about set.seed() in R

前端 未结 5 606
栀梦
栀梦 2020-12-15 18:24

I understand what set.seed() does and when I might use it, but I still have many questions about the function. Here are a few:

  1. Is it possible to \
5条回答
  •  感动是毒
    2020-12-15 19:05

    Just for fun:

    set.seed.alpha <- function(x) {
      require("digest")
      hexval <- paste0("0x",digest(x,"crc32"))
      intval <- type.convert(hexval) %% .Machine$integer.max
      set.seed(intval)
    }
    

    So you can do:

    set.seed.alpha("hello world")
    

    (in fact x can be any R object, not just an alphanumeric string)

提交回复
热议问题