5 ms·
Or just do the classic rejection sampling technique: do { x = random(-R, R) y = random(-R, R) } while (x*x + y*y > R*R)
by layoutIfNeeded 6y ago
Or just do the classic rejection sampling technique:
do {
x = random(-R, R)
y = random(-R, R)
} while (x*x + y*y > R*R)
- Sharlin 6y agoWell, that’s what the author says they started with, before replacing it with the non-uniform algorithm.
- blueblisters 6y agoThat seems awfully inefficient.
- enriquto 6y agoNot really, about π/4 = 79% of the times you will have a single iteration. The expected number of iterations is the geometric series with this ratio, which is smaller than 2.
- Sharlin 6y agoIn practice it’s likely faster than the method that uses polar coordinates due to the latter’s reliance on transcendental functions.