I’m running a script from the command line via
R CMD BATCH script.in.R script.out.R &
I have the following line, which picks 12 random row ids and sorts them:
test.index<-sort(sample(1:nrow(recoded),12))
It spits out the same 12 numbers every time if I don’t change the script. If I change it a little bit (change a label or a string or anything) then the numbers are different…I need them to be different every time!
Any ideas?
This sounds weird. What’s the rest of the script doing? If it calls (or some other function it calls)
set.seed, that would explain things, but since you say changing (what I assume to be) the data, that would imply that the seed is set to some hash of your dataset?! Or is it if you change the script in any way?Anyway, you can insert a line like
rm(.Random.seed, envir=globalenv())before your call tosample, which should reset the seed to a random one…Another way is to generate a unique seed yourself. Here’s one way based on time and process id.