GPLIB++
UniformRNG.cpp
Go to the documentation of this file.
1 #include "UniformRNG.h"
2 #include <ctime>
3 #include <boost/cast.hpp>
4 
5 using namespace std;
6 
7 namespace gplib
8  {
9  //the constructor sets up the boost random number generator
10  UniformRNG::UniformRNG() :
11  generator(static_cast<unsigned int> (std::time(NULL))), real_dist(
12  generator)
13  {
14 
15  }
16 
18  {
19  }
20 
21  float UniformRNG::GetNumber(const float low, const float high)
22  {
23  //return float between low and high
24  return low + (high - low) * GetNumber();
25  }
26 
28  {
29  //just forward the call to the boost random number generator
30  return real_dist();
31  }
32 
33  unsigned int UniformRNG::GetNumber(const unsigned int max)
34  {
35  //make an unsigned integer from the random float
36  return (boost::numeric_cast<unsigned int>(max * real_dist()));
37  }
38  }
virtual ~UniformRNG()
Definition: UniformRNG.cpp:17
virtual float GetNumber()
Returns a random float between 0 and 1.
Definition: UniformRNG.cpp:27