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 words: m
is a random integer between 0
and L^2
. The x
coordinate 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 coordinate points in on an x
,y
plane that sampled the space uniformly?