Commit 83e367e1 authored by Lukas Weber's avatar Lukas Weber
Browse files

Revert "change to the c++ random generator"

This reverts commit cb13783c.
parent f6f27588
......@@ -112,9 +112,9 @@ class odump
template <class Type> void write(Type&);
void write(std::string&);
std::ofstream binary_file;
private:
std::string filename;
std::ofstream binary_file;
std::ios_base::openmode amode;
int bmode;
int is_open;
......@@ -155,9 +155,8 @@ class idump
void read(std::string&);
void close() {if (is_open) {binary_file.close();is_open=0;}}
std::ifstream binary_file;
private:
std::ifstream binary_file;
int is_open;
};
......
......@@ -4,7 +4,6 @@
#include <functional>
#include <string>
#include <vector>
#include <mpi.h>
#include "mc.h"
#include "measurements.h"
......
#include "random.h"
#include <mpi.h>
#include <climits>
static inline luint hash(time_t t, clock_t c){
// Get a uint64 from t and c
// Better than uint32(x) in case x is floating point in [0,1]
// Based on code by Lawrence Kirby (fred@genesis.demon.co.uk)
#ifdef MCL_RNG_MT
randomnumbergenerator :: randomnumbergenerator()
{
ptr = new MTRand();
my_seed=ptr->get_seed();
}
static uint64_t differ = 0; // guarantee time-based seeds will change
randomnumbergenerator :: randomnumbergenerator(luint seed)
{
ptr = new MTRand(seed);
my_seed=ptr->get_seed();
}
#ifndef MCL_SINGLE
int myrank;
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
differ=(uint64_t)(myrank);
void randomnumbergenerator :: write(odump& d)
{
MTRand::uint32* randState;
randState = new MTRand::uint32[ MTRand::SAVE ];
ptr->save( randState );
d.write(randState,MTRand::SAVE);
d.write(my_seed);
delete [] randState;
}
void randomnumbergenerator :: read(idump& d)
{
MTRand::uint32* randState;
randState = new MTRand::uint32[ MTRand::SAVE ];
d.read(randState,MTRand::SAVE);
d.read(my_seed);
ptr->load( randState );
delete [] randState;
}
#endif
uint64_t h1 = 0;
unsigned char *p = (unsigned char *) &t;
for( size_t i = 0; i < sizeof(t); ++i )
{
h1 *= UCHAR_MAX + 2U;
h1 += p[i];
}
uint64_t h2 = 0;
p = (unsigned char *) &c;
for( size_t j = 0; j < sizeof(c); ++j )
{
h2 *= UCHAR_MAX + 2U;
h2 += p[j];
}
return ( h1 + differ++ ) ^ h2;
#ifdef MCL_RNG_SPRNG_4
randomnumbergenerator :: randomnumbergenerator()
{
int gtype = 4; //Multipl. Lagg. Fib.
ptr = SelectType(gtype);
my_seed=make_sprng_seed();
ptr->init_sprng(0, 1, my_seed, SPRNG_DEFAULT);
}
randomnumbergenerator :: randomnumbergenerator() : uniform(0,1)
randomnumbergenerator :: randomnumbergenerator(luint seed)
{
_seed = hash( time(NULL), clock());
gen.seed(_seed);
int gtype = 4; //Multipl. Lagg. Fib.
ptr = SelectType(gtype);
my_seed=seed;
ptr->init_sprng(0, 1, my_seed, SPRNG_DEFAULT);
}
randomnumbergenerator :: randomnumbergenerator(luint seed) : uniform(0,1)
void randomnumbergenerator :: write(odump& d)
{
_seed = seed;
gen.seed(seed);
char* buffer;
int buffersize=ptr->pack_sprng(&buffer);
d.write(buffersize);
d.write(buffer,buffersize);
d.write(my_seed);
delete buffer;
}
void randomnumbergenerator :: read(idump& d)
{
char* buffer;
int buffersize;
d.read(buffersize);
buffer = new char[buffersize];
d.read(buffer,buffersize);
d.read(my_seed);
ptr->unpack_sprng(buffer);
delete buffer;
}
#endif
#ifdef MCL_RNG_BOOST
void randomnumbergenerator :: write(odump& d)
{
d.binary_file << gen;
d.binary_file << uniform;
}
void randomnumbergenerator :: read(idump& d)
{
d.binary_file >> gen;
d.binary_file >> uniform;
}
randomnumbergenerator :: randomnumbergenerator()
{
rng = new boost::mt19937;
val = new boost::uniform_real<> (0.0, 1.0);
my_seed = 5489;
}
randomnumbergenerator :: randomnumbergenerator(int seed)
{
rng = new boost::mt19937;
rng->seed(seed);
val = new boost::uniform_real<> (0.0, 1.0);
my_seed = seed;
}
#endif
//
// #ifdef MCL_RNG_ACML
// randomnumbergenerator :: randomnumbergenerator(int seed)
// {
// gen = new acml_rand(seed, 0., 1.);
// }
//
// #endif
......@@ -3,25 +3,90 @@
#include "dump.h"
#include "types.h"
#include <random>
#define MCL_RNG_MT
#ifdef MCL_RNG_MT
#include "MersenneTwister.h"
class randomnumbergenerator
{
public:
randomnumbergenerator();
randomnumbergenerator(luint seed);
~randomnumbergenerator() {delete ptr;}
void write(odump&);
void read(idump&);
luint seed() {return my_seed;}
double d() {return ptr->randDblExc();} //in (0,1)
double d(double supp) {return ptr->randDblExc(supp);} //in (0,supp)
int i(int bound) {return ptr->randInt(bound-1);} //in [0,bound)
private:
MTRand* ptr;
luint my_seed;
};
#endif
#ifdef MCL_RNG_SPRNG_4
#include "sprng_cpp.h"
class randomnumbergenerator
{
public:
randomnumbergenerator();
randomnumbergenerator(luint seed);
~randomnumbergenerator() {}
~randomnumbergenerator() {delete ptr;}
void write(odump&);
void read(idump&);
double d() {return uniform(gen);} //in (0,1)
luint seed() {return _seed;}
luint seed() {return my_seed;}
double d() {return ptr->sprng();} //in (0,1)
double d(double supp) {return supp*d();} //in (0,supp)
int i(int bound) {return int(bound*d());} //in [0,bound)
std::mt19937 gen;
private:
luint _seed;
std::uniform_real_distribution<double> uniform;
Sprng * ptr;
luint my_seed;
};
#endif
#ifdef MCL_RNG_BOOST
#include <boost/random.hpp>
class randomnumbergenerator
{
public:
randomnumbergenerator();
randomnumbergenerator(int seed);
void write(odump&);
void read(idump&);
luint seed() {return my_seed;}
double d() {return (*val)(*rng);} //returns a value between 0 (excl) and 1 (excl).
double d(double supp) {return supp*d();} //returns a value between 0 (excl) and supp (excl.)
int i(int bound) {return int(bound*d());} //returns a value between 0 (incl) and bound (excl.)
private:
boost::mt19937 * rng;
boost::uniform_real<> * val;
luint my_seed;
};
#endif
// #ifdef MCL_RNG_ACML
// #warning RNG: ACML
// #include "acml_rand.h"
// class randomnumbergenerator
// {
// public:
// randomnumbergenerator(int seed);
// double d() {return (*gen)();} //returns a value between 0 (excl) and 1 (excl).
// double d(double supp) {return supp*d();} //returns a value between 0 (excl) and supp (excl.)
// int i(int bound) {return int(bound*d());} //returns a value between 0 (incl) and bound (excl.)
//
// private:
// acml_rand * gen;
//
// };
//
// #endif
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment