Skip to content
Prev 349912 / 398513 Next

Finding which seed resulted in a specific sample

On 13/04/2015 10:12, Isabel Natario wrote:
Because you never called the function set.seed(): assigning to a 
variable of that name does not help.

Also, there are far more values of the underlying seed than can be set 
using set.seed(), so this approach will not always work.  However

seed <- 0L
set.seed(seed)
x <- sample(letters,4L,replace=T)
while (sum(x == c("l","o","v","e"))<4L){ # I would have used identical()
   seed <- seed+1L
   set.seed(seed)
   x <- sample(letters,4L,replace=T)
}
seed

gave me an answer (543867)