GPLIB++
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
GAClasses
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
17
UniformRNG::~UniformRNG
()
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
27
float
UniformRNG::GetNumber
()
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
}
gplib::UniformRNG::~UniformRNG
virtual ~UniformRNG()
Definition:
UniformRNG.cpp:17
UniformRNG.h
gplib::UniformRNG::GetNumber
virtual float GetNumber()
Returns a random float between 0 and 1.
Definition:
UniformRNG.cpp:27
Generated on Wed May 25 2016 14:21:07 for GPLIB++ by
1.8.6