[R] how to initialize random seed properly ?

ryszard.czerminski@pharma.novartis.com ryszard.czerminski at pharma.novartis.com
Thu Jun 10 15:25:31 CEST 2004


Here is my best solution so far using $RANDOM in bash
or maybe somebody has "pure R"  solution ?

#!/bin/bash
for i in 1 2; do
p=tmp$i
cat > $p.R << EOF
set.seed($RANDOM)
cat('rnorm(3) =', rnorm(3), '\n')
EOF
nice R CMD BATCH --no-save --no-restore $p.R $p.log &
done
sleep 3
grep rnorm tmp[12].log

Best regards,
Ryszard





Ryszard Czerminski/PH/Novartis at PH
Sent by: r-help-bounces at stat.math.ethz.ch
06/09/2004 03:24 PM

 
        To:     r-help at stat.math.ethz.ch
        cc: 
        Subject:        [R] how to initialize random seed properly ?


I want to start R processes on multiple processors from single shell 
script
and I want all of them to have different random seeds.
One way of doing this is

        sleep 2 # (with 'sleep 1' I am often getting the same number)
               ...
        set.seed(unclass(Sys.time()))

Is there a simpler way without a need to sleep between invoking
different R processes ?

Ryszard

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list