A Handcart And Mohair A Handcart And Mohair - 3 months ago 7
R Question

Questions about set.seed() in R

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 "reset"
    set.seed()
    to something "more random" if you have called
    set.seed()
    earlier in your session? Is that even necessary?

  2. Is it possible to view the seed that R is currently using?

  3. Is there a way to make
    set.seed()
    allow alphanumeric seeds, the way one can enter them at random.org (be sure you are in the advanced mode, and see "Part 3" of the form to see what I mean)?


Answer

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)