Example for random number generator
- Author
- MIP
#include <cmath>
#include <cstring>
#include <Base/Math/Random.hh>
#include <Base/Debug/TimeMeasure.hh>
using namespace BIAS;
using namespace std;
#define HIST_BIN_COUNT 64
int main()
{
double num;
unsigned int hist[HIST_BIN_COUNT];
double min=-100.0, max=100.0;
long unsigned int count=100000;
long unsigned int sumuniform=0;
memset((void *)hist, 0, HIST_BIN_COUNT*sizeof(unsigned int));
double *uniform=new double[count];
cerr << "getting "<<count<<" uniform distributed random vars took "
for (register unsigned int i=0; i<count; i++){
num = uniform[i];
hist[(unsigned int)floor((num-min)/(max-min)*HIST_BIN_COUNT)]++;
}
for (int i=0; i< HIST_BIN_COUNT; i++){
cout << i << ": \t" << hist[i] << endl;
sumuniform+=hist[i];
}
cerr << "got "<<sumuniform<<" uniform distributed vars\n";
sumuniform=0;
delete[] uniform;
return 0;
}