Consider the following functions for generating random numbers:
Code:
double uniform_deviate( int seed ){
return seed * ( 1.0 / ( RAND_MAX + 1.0 ) );
}
int get_rand( int UPPER_BOUND ){
return static_cast<int>( uniform_deviate( rand() ) * UPPER_BOUND );
}
int get_rand( int LOWER_BOUND, int UPPER_BOUND ){
return static_cast<int>( LOWER_BOUND + uniform_deviate( rand() ) * ( UPPER_BOUND - LOWER_BOUND ) );
}
I'd like to write the following function get_rand() with no arguments:
Code:
int get_rand(){
// ...
}
To use in this normal distribution function:
Code:
double normal(const double &mean, const double &sdiv){
static const double PI = 3.1415927;
static const double R_MAX = RAND_MAX + 1;
return sdiv * sqrt( -2 * log( ( rand() + 1 )/R_MAX) ) * sin( 2 * PI * rand()/R_MAX ) + mean;
}
My question is how do implement get_rand() with no arguments to replace the calls to rand() in the normal() function? Is it even necessary?
Thoughts?