ALPSCore reference
random01.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #pragma once
8 
9 #include <alps/hdf5/archive.hpp>
10 
11 #include <boost/random.hpp>
12 
13 #include <string>
14 #include <sstream>
15 
16 namespace alps {
17 
18  struct random01 : public boost::variate_generator<boost::mt19937, boost::uniform_01<double> > {
19  random01(int seed = 42)
20  : boost::variate_generator<boost::mt19937, boost::uniform_01<double> >(boost::mt19937(seed), boost::uniform_01<double>())
21  {}
22 
23  void save(alps::hdf5::archive & ar) const { // TODO: move this to hdf5 archive!
24  std::ostringstream os;
25  os << this->engine();
26  ar["engine"] << os.str();
27  }
28 
29  void load(alps::hdf5::archive & ar) { // TODO: move this to hdf5 archive!
30  std::string state;
31  ar["engine"] >> state;
32  std::istringstream is(state);
33  is >> this->engine();
34  }
35  };
36 
37 }
void load(alps::hdf5::archive &ar)
Definition: random01.hpp:29
random01(int seed=42)
Definition: random01.hpp:19
void save(alps::hdf5::archive &ar) const
Definition: random01.hpp:23