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;
}
Unless I misread your question, I would expect to see something like this Java code:
I print these values, but you probably want to store them in a data structure that you can feed to your Monte Carlo simulation for evaluation.