
Our triangle is a thin sliver so AB and BC are essentially parallel.


pick a pair of random numbers x and y uniformly on giving distances from the center. Picking a random point in ABCD is easy using the above method. Again, extend to ABCD, where D is now twice the radius from the circle center. So we now need to generate a distance from the center by picking a point in the sliver ABC. We can pick one of these triangles simply by picking an angle theta. In the limit we can think of it as infinitely many isoceles triangles ABC with B at the origin and A and C on the circumference vanishingly close to each other. To get a uniformly chosen point in the original triangle we just fold any points that appear in ADC back down to ABC along AC. We uniformly pick a random point X on AB and Y on BC and choose Z such that XBYZ is a parallelogram. It's easy to generate points uniformly in ABCD. How can we generate a point uniformly in a triangle ABC, where |AB|=|BC|? Let's make this easier by extending to a parallelogram ABCD. Let's approach this like Archimedes would have. Step 3: Apply the resulting function to a uniform value between 0 and 1 Mathematically this boils down to swapping x and y and solving for y: Since we're working with reals, the CDF is expressed as the integral of the PDF.
MATH.RANDOM JAVA FORMULA PDF
…so, back to generating random radius values where our PDF equals 2 x. To get values according to the desired distribution, we use CDF -1(random()).

This is why we mirror the whole thing x becomes y and y becomes x: We can only "shoot bullets from the ground straight up"! We need the inverse function! The problem is that for this function, the y axis is the output and the x axis is the input. See how the density of the bullets on the ground correspond to our desired distribution! We're almost there! As the bullets hit the line, they drop down to the ground: To see how this is useful, imagine that we shoot bullets from left to right at uniformly distributed heights. Intuitively: While PDF( x) describes the number of random values at x, CDF( x) describes the number of random values less than x. The CDF is, as the name suggests, the cumulative version of the PDF.

Since the circumference of a circle (2π r) grows linearly with r, it follows that the number of random points should grow linearly with r. This means for example, that looking on the perimeter of a circle with circumference 2 we should find twice as many points as the number of points on the perimeter of a circle with circumference 1. The average distance between points should be the same regardless of how far from the center we look. Assume for simplicity that we're working with the unit circle, i.e. Let's look at the math that leads up to sqrt(random()). If you want to convert this to Cartesian coordinates, you can do x = centerX + r * cos(theta) (Assuming random() gives a value between 0 and 1 uniformly)
MATH.RANDOM JAVA FORMULA HOW TO
How to generate a random point within a circle of radius R: r = R * sqrt(random())
