00001
00002
00003
00004
00005
00006 #include "PlayaRand.hpp"
00007 #include "PlayaMPIComm.hpp"
00008 #include "Teuchos_Assert.hpp"
00009 #include "PlayaOut.hpp"
00010
00011 namespace Playa
00012 {
00013
00014 void Rand::setLocalSeed(const MPIComm& comm, int seed)
00015 {
00016 int rank = comm.getRank();
00017 int lseed = seed;
00018 for (int i=0; i<rank; i++) lseed = (lseed * 371761) % 5476181;
00019
00020 #ifdef _WIN32
00021 srand((long) lseed);
00022 #else
00023 srand48(lseed);
00024 #endif
00025 }
00026
00027 double Rand::val()
00028 {
00029 #ifdef _WIN32
00030 return ((double) rand())/RAND_MAX;
00031 #else
00032 return drand48();
00033 #endif
00034 }
00035
00036
00037 }