rand.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #include "rand.h"
15 #include "xthread.h"
16 
17 #ifdef USE_STD_RANDOM
18 //C++11
19  #include <random>
20  struct Rand {
21  Rand() : un01(0.0, 1.0) {}
22  std::mt19937 rng_mt19937;
23  std::uniform_real_distribution<> un01;
24  };
25  static XThreadLocal<Rand> stl_rand;
26  double randMT19937() {
27  return stl_rand->un01( stl_rand->rng_mt19937);
28  }
29 #else
30  static XMutex s_mutex;
31  #include <boost/random/mersenne_twister.hpp>
32  #include <boost/random/uniform_01.hpp>
33 
34  static boost::mt19937 s_rng_mt19937;
35  static boost::uniform_01<boost::mt19937> s_rng_un01_mt19937(s_rng_mt19937);
36  double randMT19937() {
37  XScopedLock<XMutex> lock(s_mutex);
38  return s_rng_un01_mt19937();
39  }
40 #endif
41 

Generated for KAME4 by  doxygen 1.8.3