57 static const double prec = 4.6566128E-10;
63 table[seq1][
col] -= (index&0x3FFFFFFF);
64 while (
table[seq1][col] <= 0)
table[seq1][
col] += (modulus-1);
70 int numEngines = numberOfEngines++;
75 long mask = ((cycle & 0x007fffff) << 8);
76 for (
int i=0; i<2; ++i) {
77 for (
int j=0; j<
maxSeq; ++j) {
91 long mask = ((cycle & 0x000007ff) << 20);
92 for (
int j=0; j<
maxSeq; ++j) {
140 std::ofstream outFile( filename, std::ios::out ) ;
142 if (!outFile.bad()) {
144 std::vector<unsigned long>
v =
put();
145 for (
unsigned int i=0; i<v.size(); ++i) {
146 outFile << v[i] <<
"\n";
155 std::cerr <<
" -- Engine state remains unchanged\n";
159 std::vector<unsigned long>
v;
164 inFile.clear(std::ios::badbit | inFile.rdstate());
165 std::cerr <<
"\nJamesRandom state (vector) description improper."
166 <<
"\nrestoreStatus has failed."
167 <<
"\nInput stream is probably mispositioned now." << std::endl;
176 if (!inFile.bad() && !inFile.eof()) {
178 for (
int i=0; i<2; ++i)
186 std::cout << std::endl;
187 std::cout <<
"--------- Ranecu engine status ---------" << std::endl;
188 std::cout <<
" Initial seed (index) = " <<
theSeed << std::endl;
189 std::cout <<
" Current couple of seeds = "
192 std::cout <<
"----------------------------------------" << std::endl;
197 const int index =
seq;
198 long seed1 =
table[index][0];
199 long seed2 =
table[index][1];
205 if (seed1 < 0) seed1 +=
shift1;
207 if (seed2 < 0) seed2 +=
shift2;
209 table[index][0] = seed1;
210 table[index][1] = seed2;
212 long diff = seed1-seed2;
214 if (diff <= 0) diff += (
shift1-1);
215 return (
double)(diff*
prec);
220 const int index =
seq;
221 long seed1 =
table[index][0];
222 long seed2 =
table[index][1];
226 for (i=0; i<size; ++i)
232 if (seed1 < 0) seed1 +=
shift1;
234 if (seed2 < 0) seed2 +=
shift2;
236 long diff = seed1-seed2;
237 if (diff <= 0) diff += (
shift1-1);
239 vect[i] = (double)(diff*
prec);
241 table[index][0] = seed1;
242 table[index][1] = seed2;
245 RanecuEngine::operator double() {
249 RanecuEngine::operator float() {
250 return float(
flat() );
253 RanecuEngine::operator
unsigned int() {
254 const int index = seq;
255 long seed1 = table[index][0];
256 long seed2 = table[index][1];
258 int k1 = (
int)(seed1/ecuyer_b);
259 int k2 = (
int)(seed2/ecuyer_e);
261 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
262 if (seed1 < 0) seed1 += shift1;
263 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
264 if (seed2 < 0) seed2 += shift2;
266 table[index][0] = seed1;
267 table[index][1] = seed2;
268 long diff = seed1-seed2;
269 if( diff <= 0 ) diff += (shift1-1);
271 return ((diff << 1) | (seed1&1))& 0xffffffff;
276 char beginMarker[] =
"RanecuEngine-begin";
277 os << beginMarker <<
"\nUvec\n";
278 std::vector<unsigned long>
v =
put();
279 for (
unsigned int i=0; i<v.size(); ++i) {
286 std::vector<unsigned long>
v;
287 v.push_back (engineIDulong<RanecuEngine>());
288 v.push_back(static_cast<unsigned long>(
theSeed));
289 v.push_back(static_cast<unsigned long>(
table[
theSeed][0]));
290 v.push_back(static_cast<unsigned long>(
table[theSeed][1]));
303 if (strcmp(beginMarker,
"RanecuEngine-begin")) {
304 is.clear(std::ios::badbit | is.rdstate());
305 std::cerr <<
"\nInput stream mispositioned or"
306 <<
"\nRanecuEngine state description missing or"
307 <<
"\nwrong engine type found." << std::endl;
314 return "RanecuEngine-begin";
320 std::vector<unsigned long>
v;
325 is.clear(std::ios::badbit | is.rdstate());
326 std::cerr <<
"\nRanecuEngine state (vector) description improper."
327 <<
"\ngetState() has failed."
328 <<
"\nInput stream is probably mispositioned now." << std::endl;
339 for (
int i=0; i<2; ++i) {
345 if (strcmp(endMarker,
"RanecuEngine-end")) {
346 is.clear(std::ios::badbit | is.rdstate());
347 std::cerr <<
"\nRanecuEngine state description incomplete."
348 <<
"\nInput stream is probably mispositioned now." << std::endl;
357 if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
359 "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
368 "\nRanecuEngine get:state vector has wrong length - state unchanged\n";