Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions about set.seed() in R

Tags:

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)?
like image 894
A5C1D2H2I1M1N2O1R2T1 Avatar asked Jun 06 '12 08:06

A5C1D2H2I1M1N2O1R2T1


1 Answers

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)

like image 169
Ben Bolker Avatar answered Sep 27 '22 19:09

Ben Bolker