58 static const double prec = 4.6566128E-10;
64 table[seq1][
col] -= (index&0x3FFFFFFF);
65 while (
table[seq1][col] <= 0)
table[seq1][
col] += (modulus-1);
71 int numEngines = numberOfEngines++;
72 int cycle = std::abs(
int(numEngines/
maxSeq));
76 long mask = ((cycle & 0x007fffff) << 8);
77 for (
int i=0; i<2; ++i) {
78 for (
int j=0; j<
maxSeq; ++j) {
89 int cycle = std::abs(
int(index/
maxSeq));
92 long mask = ((cycle & 0x000007ff) << 20);
93 for (
int j=0; j<
maxSeq; ++j) {
141 std::ofstream outFile( filename, std::ios::out ) ;
143 if (!outFile.bad()) {
145 std::vector<unsigned long> v =
put();
146 for (
unsigned int i=0; i<v.size(); ++i) {
147 outFile << v[i] <<
"\n";
156 std::cerr <<
" -- Engine state remains unchanged\n";
160 std::vector<unsigned long> v;
165 inFile.clear(std::ios::badbit | inFile.rdstate());
166 std::cerr <<
"\nJamesRandom state (vector) description improper."
167 <<
"\nrestoreStatus has failed."
168 <<
"\nInput stream is probably mispositioned now." << std::endl;
177 if (!inFile.bad() && !inFile.eof()) {
179 for (
int i=0; i<2; ++i)
187 std::cout << std::endl;
188 std::cout <<
"--------- Ranecu engine status ---------" << std::endl;
189 std::cout <<
" Initial seed (index) = " <<
theSeed << std::endl;
190 std::cout <<
" Current couple of seeds = "
193 std::cout <<
"----------------------------------------" << std::endl;
198 const int index =
seq;
199 long seed1 =
table[index][0];
200 long seed2 =
table[index][1];
206 if (seed1 < 0) seed1 +=
shift1;
208 if (seed2 < 0) seed2 +=
shift2;
210 table[index][0] = seed1;
211 table[index][1] = seed2;
213 long diff = seed1-seed2;
215 if (diff <= 0) diff += (
shift1-1);
216 return (
double)(diff*
prec);
221 const int index =
seq;
222 long seed1 =
table[index][0];
223 long seed2 =
table[index][1];
227 for (i=0; i<size; ++i)
233 if (seed1 < 0) seed1 +=
shift1;
235 if (seed2 < 0) seed2 +=
shift2;
237 long diff = seed1-seed2;
238 if (diff <= 0) diff += (
shift1-1);
240 vect[i] = (double)(diff*
prec);
242 table[index][0] = seed1;
243 table[index][1] = seed2;
246 RanecuEngine::operator double() {
250 RanecuEngine::operator float() {
251 return float(
flat() );
254 RanecuEngine::operator
unsigned int() {
255 const int index = seq;
256 long seed1 = table[index][0];
257 long seed2 = table[index][1];
259 int k1 = (
int)(seed1/ecuyer_b);
260 int k2 = (
int)(seed2/ecuyer_e);
262 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
263 if (seed1 < 0) seed1 += shift1;
264 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
265 if (seed2 < 0) seed2 += shift2;
267 table[index][0] = seed1;
268 table[index][1] = seed2;
269 long diff = seed1-seed2;
270 if( diff <= 0 ) diff += (shift1-1);
272 return ((diff << 1) | (seed1&1))& 0xffffffff;
277 char beginMarker[] =
"RanecuEngine-begin";
278 os << beginMarker <<
"\nUvec\n";
279 std::vector<unsigned long> v =
put();
280 for (
unsigned int i=0; i<v.size(); ++i) {
287 std::vector<unsigned long> v;
288 v.push_back (engineIDulong<RanecuEngine>());
289 v.push_back(static_cast<unsigned long>(
theSeed));
290 v.push_back(static_cast<unsigned long>(
table[
theSeed][0]));
291 v.push_back(static_cast<unsigned long>(
table[theSeed][1]));
304 if (strcmp(beginMarker,
"RanecuEngine-begin")) {
305 is.clear(std::ios::badbit | is.rdstate());
306 std::cerr <<
"\nInput stream mispositioned or"
307 <<
"\nRanecuEngine state description missing or"
308 <<
"\nwrong engine type found." << std::endl;
315 return "RanecuEngine-begin";
321 std::vector<unsigned long> v;
326 is.clear(std::ios::badbit | is.rdstate());
327 std::cerr <<
"\nRanecuEngine state (vector) description improper."
328 <<
"\ngetState() has failed."
329 <<
"\nInput stream is probably mispositioned now." << std::endl;
340 for (
int i=0; i<2; ++i) {
346 if (strcmp(endMarker,
"RanecuEngine-end")) {
347 is.clear(std::ios::badbit | is.rdstate());
348 std::cerr <<
"\nRanecuEngine state description incomplete."
349 <<
"\nInput stream is probably mispositioned now." << std::endl;
358 if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
360 "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
369 "\nRanecuEngine get:state vector has wrong length - state unchanged\n";
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
static const int ecuyer_c
void restoreStatus(const char filename[]="Ranecu.conf")
static std::string engineName()
static const G4double pos
void setSeeds(const long *seeds, int index=-1)
void setSeed(long index, int dum=0)
static const int ecuyer_a
virtual std::istream & getState(std::istream &is)
void setIndex(long index)
static const int MarkerLen
#define CLHEP_ATOMIC_INT_TYPE
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
virtual std::istream & get(std::istream &is)
void flatArray(const int size, double *vect)
static const unsigned int VECTOR_STATE_SIZE
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static void getTheTableSeeds(long *seeds, int index)
void further_randomize(int seq, int col, int index, int modulus)
static const int ecuyer_b
std::vector< unsigned long > put() const
void saveStatus(const char filename[]="Ranecu.conf") const
static const int ecuyer_d
static const int ecuyer_f
static std::string beginTag()
static const int ecuyer_e