I'm trying to find a way of choosing random lattice points in an x,y plane. It is suggested that I use the following code:
//////////////////////
// Pick random site //
//////////////////////
int m=int(rand()*1.0/RAND_MAX*L*L);
int mx=m%L; //x coordinate of m site
int my=int(m*1.0/L); // y coordinate of m site
In other word: m is a random integer between 0 and L^2. The x co-ordinate is m mod L, which is a number between 0 and L. y is set as the closest integer to m/L, which is an integer between 0 and L.
It seems to work, but in L^2 runs, are we more likely to search one part of the x,y system than another? Could anyone explain why, and whether there is an alternative method for picking random co-ordiante points in on an x,y plane that sampled the space uniformly.
Aucun commentaire:
Enregistrer un commentaire