NeoPZ
TPZUniformRandom.h
Go to the documentation of this file.
1 /*
2  * File: TPZUniformRandom.h
3  * Author: quinelato
4  *
5  * Created on 5 de Dezembro de 2017, 13:31
6  */
7 
8 #ifndef TPZUNIFORMRANDOM_H
9 #define TPZUNIFORMRANDOM_H
10 
11 #include <random>
12 #include <functional>
13 #include <ctime>
14 
15 #include "TPZConstrainedRandom.h"
16 
17 template <typename TVar>
18 class TPZUniformRandom : public TPZConstrainedRandom<TVar> {
19 public:
20  TPZUniformRandom(TVar begin, TVar end) : TPZConstrainedRandom<TVar>(begin, end), generator(std::bind(std::uniform_real_distribution<TVar>(begin, end), std::default_random_engine(clock()))) {
21 }
23 
24  }
25 
26  virtual TPZRandom<TVar> *clone(){
27  return new TPZUniformRandom<TVar>(*this);
28  }
29 
30  TVar next(){
31  return generator();
32  }
33 
34  TVar pdf(TVar x);
35 
36  virtual ~TPZUniformRandom(){
37 
38  }
39 protected:
40  std::function<TVar()> generator;
41 };
42 
43 template <typename TVar>
45  return 1./(this->fend - this->fbegin);
46 }
47 
48 #endif /* TPZUNIFORMRANDOM_H */
49 
TVar pdf(TVar x)
TPZUniformRandom(TVar begin, TVar end)
std::function< TVar()> generator
virtual TPZRandom< TVar > * clone()
TPZUniformRandom(const TPZUniformRandom< TVar > &orig)
virtual ~TPZUniformRandom()