I am trying to generate a certain amount of random uniform points inside a rectangle (I know the pair of coordinates for each corner).
Let our rectangle be ABCD
My idea is: Divide the rectangle into two triangles by the AC diagonal. Find the slope and the intercept of the diagonal. Then, generate two random numbers from [0,1] interval, let them be a,b. Evaluate x = aAB and y = bAD (AB, AD, distances). If A is not (0,0), then we can add to x and y A's coordinates. Now we have a point (x,y). If it is not in the lower triangle (ABC), skip to the next step. Else, add the point to our plot and also add the symmetric of (x,y) vs. the AC diagonal so that we can fill the upper triangle (ADC) too.
I have implemented this, but I highly doubt that the points are uniformly generated (judging from the plot). How should I modify my algorithm? I guess that the issue is related to how I pick the triangle and the symmetric thing.