I would like to generate points(x,y) uniformly on rectangle. First You input minX and maxX and minY maxY and then you generate the (x,y) uniformly, The basic code is shown below is any better way to achive it? (I need it to monte carlo method to make a plot)
#include <iostream>
#include <random>
double drand(const double min = 0., const double max = 1.)
{
return (max - min) * static_cast<double>(rand()) / static_cast<double> (RAND_MAX)+min;
}
int main(int argc, char **argv)
{
for(unsigned short int i=0;i<1000;++i)
{
std::cout << "x " << drand(minX, maxX) << std::endl;
std::cout << "y " << drand(0., maxY) << std::endl;
}
return 0;
}
You're using
rand(). Your barrier isn't all that high since almost anything is better thanrand(). Since you apparently have C++11, why don't you use the much superior random number generators offered by C++11? For example,