SOFA API  ca665544
Open source framework for multi-physics simuation
sofa::helper::RandomGenerator Class Reference

#include <RandomGenerator.h>

Detailed Description

Generate Random number based on random functions from OpenBSD

Public Member Functions

 RandomGenerator ()
 
 RandomGenerator (long seed)
 
virtual ~RandomGenerator ()
 
void initSeed (long seed)
 
template<class T >
random (T min, T max)
 
template<class T >
symrand (T vmax)
 number between [-vmax, vmax] (vmax has less chance to appear) More...
 
template<class T >
random ()
 
template<>
long random (long min, long max)
 
template<>
double random (double min, double max)
 
template<>
float random (float min, float max)
 
template<>
bool random (bool, bool)
 
template<>
double random ()
 

Protected Member Functions

unsigned long int randomBase ()
 integer between [0, 2^32-1) More...
 

Constructor details

◆ RandomGenerator() [1/2]

sofa::helper::RandomGenerator::RandomGenerator ( )

◆ RandomGenerator() [2/2]

sofa::helper::RandomGenerator::RandomGenerator ( long  seed)

◆ ~RandomGenerator()

sofa::helper::RandomGenerator::~RandomGenerator ( )
virtual

Function details

◆ initSeed()

void sofa::helper::RandomGenerator::initSeed ( long  seed)

◆ random() [1/7]

template<class T >
T sofa::helper::RandomGenerator::random ( )
inline

number between [T::min, T::max) (max has less chance to appear) note that "only" 2^32 different values can be generated

Warning
for floating types, min = -(2^32-1) & max = (2^32-1)

◆ random() [2/7]

template<>
float sofa::helper::RandomGenerator::random ( )
inline

◆ random() [3/7]

template<>
bool sofa::helper::RandomGenerator::random ( bool  ,
bool   
)
inline

◆ random() [4/7]

template<>
double sofa::helper::RandomGenerator::random ( double  min,
double  max 
)
inline

◆ random() [5/7]

template<>
float sofa::helper::RandomGenerator::random ( float  min,
float  max 
)
inline

◆ random() [6/7]

template<>
long sofa::helper::RandomGenerator::random ( long  min,
long  max 
)
inline

◆ random() [7/7]

template<class T >
T sofa::helper::RandomGenerator::random ( min,
max 
)
inline

number between [min, max) (max has less chance to appear) note that "only" 2^32 different values can be generated

Warning
min < max
for floating types a too large range can generate inf

◆ randomBase()

unsigned long sofa::helper::RandomGenerator::randomBase ( )
protected

integer between [0, 2^32-1)

◆ symrand()

template<class T >
T sofa::helper::RandomGenerator::symrand ( vmax)
inline

number between [-vmax, vmax] (vmax has less chance to appear)