[math] Generate a random point within a circle (uniformly)

First we generate a cdf[x] which is

The probability that a point is less than distance x from the centre of the circle. Assume the circle has a radius of R.

obviously if x is zero then cdf[0] = 0

obviously if x is R then the cdf[R] = 1

obviously if x = r then the cdf[r] = (Pi r^2)/(Pi R^2)

This is because each "small area" on the circle has the same probability of being picked, So the probability is proportionally to the area in question. And the area given a distance x from the centre of the circle is Pi r^2

so cdf[x] = x^2/R^2 because the Pi cancel each other out

we have cdf[x]=x^2/R^2 where x goes from 0 to R

So we solve for x

R^2 cdf[x] = x^2

x = R Sqrt[ cdf[x] ]

We can now replace cdf with a random number from 0 to 1

x = R Sqrt[ RandomReal[{0,1}] ]

Finally

r = R Sqrt[  RandomReal[{0,1}] ];
theta = 360 deg * RandomReal[{0,1}];
{r,theta}

we get the polar coordinates {0.601168 R, 311.915 deg}

Examples related to math

How to do perspective fixing? How to pad a string with leading zeros in Python 3 How can I use "e" (Euler's number) and power operation in python 2.7 numpy max vs amax vs maximum Efficiently getting all divisors of a given number Using atan2 to find angle between two vectors How to calculate percentage when old value is ZERO Finding square root without using sqrt function? Exponentiation in Python - should I prefer ** operator instead of math.pow and math.sqrt? How do I get the total number of unique pairs of a set in the database?

Examples related to random

How can I get a random number in Kotlin? scikit-learn random state in splitting dataset Random number between 0 and 1 in python In python, what is the difference between random.uniform() and random.random()? Generate random colors (RGB) Random state (Pseudo-random number) in Scikit learn How does one generate a random number in Apple's Swift language? How to generate a random string of a fixed length in Go? Generate 'n' unique random numbers within a range What does random.sample() method in python do?

Examples related to geometry

Circle button css Using atan2 to find angle between two vectors How do I compute the intersection point of two lines? Creating a triangle with for loops Plotting a 3d cube, a sphere and a vector in Matplotlib How to find the Center Coordinate of Rectangle? Evenly distributing n points on a sphere How do CSS triangles work? How to draw circle in html page? Generate a random point within a circle (uniformly)

Examples related to probability

Normalizing a list of numbers in Python Find the similarity metric between two strings How to calculate probability in a normal distribution given mean & standard deviation? Generate a random point within a circle (uniformly) How to calculate mean, median, mode and range from a set of numbers