Message: random num generator initialization Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question random num generator initialization 

Forum: Run Management
Date: 03 Dec, 2009
From: Valery Taranenko <Valery Taranenko>

I'd like to initialize my RNG (rand num generator) with different seeds at different times (I submit many jobs with the same inputs). I use the following on Linux:

  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
  std::fstream randomFile;
  randomFile.open("/dev/urandom", std::ios::in | std::ios::binary);
  unsigned int seed;
  randomFile.read(reinterpret_cast<char *>(&seed), sizeof(unsigned int));
  randomFile.close();
  G4cout << "Random seed is " << seed << G4endl;

  //G4int seed=time(NULL);

  CLHEP::HepRandom::setTheSeed(seed);

--- now, the question is: how i'm gonna code it on Windows where /dev/urandom is not available. we need a portable code for this very common task.

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: random num generator initialization   (Tom Roberts - 03 Dec, 2009)
(_ Agree: Re: random num generator initialization   (Valery Taranenko - 03 Dec, 2009)
(_ None: Re: random num generator initialization   (Tom Roberts - 03 Dec, 2009)
 Add Message Add Message
to: "random num generator initialization"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]