NGL  6.5
The NCCA Graphics Library
ngl::Random Class Reference

wrapper for std random and distribution functions, it will generate two basic random functions for RandPositiveFloat (0-1) and RandFloat() +/- 1 these are also overloaded to have a param for range added to this are functions for Random Colours and Vectors and Points and also the ability to add other distributions random library. More...

#include <Random.h>

+ Inheritance diagram for ngl::Random:
+ Collaboration diagram for ngl::Random:

Public Member Functions

void setSeed ()
 set the seed using std::time(NULL) More...
 
void setSeed (unsigned int _value)
 set the seed using a param value More...
 
Real getFloatFromGeneratorName (const std::string &_name)
 gets a pre-generated Real value for a genetator More...
 
Colour getRandomColour ()
 return a random colour with rgb components clamped between 0-1 More...
 
Colour getRandomColourAndAlpha ()
 return a random colour with rgba components clamped between 0-1 More...
 
Vec4 getRandomVec4 ()
 get a random vector with componets ranged from +/- 1 More...
 
Vec4 getRandomNormalizedVec4 ()
 get a random vector with componets ranged from +/- 1 and Normalized More...
 
Vec3 getRandomVec3 ()
 get a random vector with componets ranged from +/- 1 More...
 
Vec3 getRandomNormalizedVec3 ()
 get a random vector with componets ranged from +/- 1 and Normalized More...
 
Vec2 getRandomVec2 ()
 get a random vector with componets ranged from +/- 1 More...
 
Vec2 getRandomNormalizedVec2 ()
 get a random vector with componets ranged from +/- 1 and Normalized More...
 
Vec3 getRandomPoint (Real _xRange=1.0, Real _yRange=1.0, Real _zRange=1.0)
 get a random point in 3D space defaults to +/- 1 else user defined range More...
 
Real randomNumber (Real _mult=1)
 a replacement for the old RandomNumber func this is basically a convinience function More...
 
Real randomPositiveNumber (Real _mult=1)
 a replacement for the old ReandomPosNum this is basically a convinience function More...
 
- Public Member Functions inherited from ngl::Singleton< Random >
 Singleton (const Singleton &)=delete
 
Singletonoperator= (const Singleton &)=delete
 

Protected Member Functions

 Random ()
 ctor hidden in protected as we are a singleton class More...
 
- Protected Member Functions inherited from ngl::Singleton< Random >
 Singleton ()
 Constructor. More...
 
virtual ~Singleton ()
 Destructor. More...
 

Protected Attributes

std::mt19937 m_generator
 the generator for rng class where all funcs and distribs are added. all we need to do is replace this one define to use any of the other boost rng engines. More...
 
std::unordered_map< std::string, std::uniform_real_distribution< Real > > m_floatGenerators
 our map to hold the generator data basically we are going to hold a name / function pair, and this function will be called returning a Real value More...
 

Friends

class Singleton< Random >
 we are a friend with singelton so we can assess the template methods More...
 
class Colour
 
class Vec4
 

Additional Inherited Members

- Static Public Member Functions inherited from ngl::Singleton< Random >
static Randominstance ()
 Get the instance. More...
 
- Static Protected Member Functions inherited from ngl::Singleton< Random >
static void killSingleton ()
 
- Static Protected Attributes inherited from ngl::Singleton< Random >
static Randoms_instance
 unique instance of the singleton More...
 

Detailed Description

wrapper for std random and distribution functions, it will generate two basic random functions for RandPositiveFloat (0-1) and RandFloat() +/- 1 these are also overloaded to have a param for range added to this are functions for Random Colours and Vectors and Points and also the ability to add other distributions random library.

Note
by default we use the mt19937 mersenne twister but this can be changed in the library by modifying the define ENGINE to any of the following
as each call to the random generator function accesses the ENGINE m_generator no callable method that invokes any of the generators can be constant as the internal state of m_generator is modified with the call hence the lack of const methods
Author
Jonathan Macey
Version
1.0
Date
17/05/10 Initial version

Definition at line 66 of file Random.h.

Constructor & Destructor Documentation

ngl::Random::Random ( )
protected

ctor hidden in protected as we are a singleton class

Definition at line 46 of file Random.cpp.

References m_floatGenerators, ngl::RandomFloat, and ngl::RandomPositiveFloat.

Member Function Documentation

Real ngl::Random::getFloatFromGeneratorName ( const std::string _name)

gets a pre-generated Real value for a genetator

Parameters
_namethe name of the generator to use for the number returns a random number created by the generator or 0 if the generator is not found

Definition at line 60 of file Random.cpp.

References m_floatGenerators, and m_generator.

Colour ngl::Random::getRandomColour ( )

return a random colour with rgb components clamped between 0-1

Definition at line 80 of file Random.cpp.

References Colour, m_floatGenerators, m_generator, and ngl::RandomPositiveFloat.

Colour ngl::Random::getRandomColourAndAlpha ( )

return a random colour with rgba components clamped between 0-1

Definition at line 88 of file Random.cpp.

References Colour, m_floatGenerators, m_generator, and ngl::RandomPositiveFloat.

Vec2 ngl::Random::getRandomNormalizedVec2 ( )

get a random vector with componets ranged from +/- 1 and Normalized

Definition at line 137 of file Random.cpp.

References m_floatGenerators, m_generator, ngl::Vec2::normalize(), and ngl::RandomFloat.

+ Here is the call graph for this function:

Vec3 ngl::Random::getRandomNormalizedVec3 ( )

get a random vector with componets ranged from +/- 1 and Normalized

Definition at line 121 of file Random.cpp.

References m_floatGenerators, m_generator, ngl::Vec3::normalize(), and ngl::RandomFloat.

+ Here is the call graph for this function:

Vec4 ngl::Random::getRandomNormalizedVec4 ( )

get a random vector with componets ranged from +/- 1 and Normalized

Definition at line 104 of file Random.cpp.

References m_floatGenerators, m_generator, ngl::Vec4::normalize(), and ngl::RandomFloat.

+ Here is the call graph for this function:

Vec3 ngl::Random::getRandomPoint ( Real  _xRange = 1.0,
Real  _yRange = 1.0,
Real  _zRange = 1.0 
)

get a random point in 3D space defaults to +/- 1 else user defined range

Parameters
_xRangethe +/-x range
_yRangethe +/-y range
_zRangethe +/-z range
Returns
a random point

Definition at line 148 of file Random.cpp.

References m_floatGenerators, m_generator, and ngl::RandomFloat.

Vec2 ngl::Random::getRandomVec2 ( )

get a random vector with componets ranged from +/- 1

Definition at line 130 of file Random.cpp.

References m_floatGenerators, m_generator, and ngl::RandomFloat.

Vec3 ngl::Random::getRandomVec3 ( )

get a random vector with componets ranged from +/- 1

Definition at line 114 of file Random.cpp.

References m_floatGenerators, m_generator, and ngl::RandomFloat.

Vec4 ngl::Random::getRandomVec4 ( )

get a random vector with componets ranged from +/- 1

Definition at line 97 of file Random.cpp.

References m_floatGenerators, m_generator, ngl::RandomFloat, and Vec4.

Real ngl::Random::randomNumber ( Real  _mult = 1)

a replacement for the old RandomNumber func this is basically a convinience function

Parameters
_multan optional multiplyer for the output
Returns
(uniform_random(-1-0-+1) * _mult)

Definition at line 157 of file Random.cpp.

References m_floatGenerators, m_generator, and ngl::RandomFloat.

Real ngl::Random::randomPositiveNumber ( Real  _mult = 1)

a replacement for the old ReandomPosNum this is basically a convinience function

Parameters
_multan optional multiplyer for the output
Returns
(uniform_random(0-1) * _mult)

Definition at line 164 of file Random.cpp.

References m_floatGenerators, m_generator, and ngl::RandomPositiveFloat.

void ngl::Random::setSeed ( )

set the seed using std::time(NULL)

Definition at line 32 of file Random.cpp.

References m_generator.

void ngl::Random::setSeed ( unsigned int  _value)

set the seed using a param value

Parameters
_valuethe seed value

Definition at line 39 of file Random.cpp.

References m_generator.

Friends And Related Function Documentation

friend class Colour
friend

Definition at line 72 of file Random.h.

friend class Singleton< Random >
friend

we are a friend with singelton so we can assess the template methods

Definition at line 71 of file Random.h.

friend class Vec4
friend

Definition at line 73 of file Random.h.

Member Data Documentation

std::unordered_map<std::string, std::uniform_real_distribution<Real> > ngl::Random::m_floatGenerators
protected

our map to hold the generator data basically we are going to hold a name / function pair, and this function will be called returning a Real value

Definition at line 178 of file Random.h.

std::mt19937 ngl::Random::m_generator
protected

the generator for rng class where all funcs and distribs are added. all we need to do is replace this one define to use any of the other boost rng engines.

Definition at line 166 of file Random.h.


The documentation for this class was generated from the following files: