Re:Uniformly Sample Points in a Disk
by eru on Thursday May 26, 2022 @11:38PM
(#31525794)
Here's a much simpler way to get the same distribution (in JavaScript syntax):
var radius1 = Math.max(Math.random(), Math.random());
var radius2 = Math.sqrt(Math.random());
Basically taking the maximum of two uniformly distributed random variables is the same as taking the square root of one of them in terms of their distributions.
Whether taking the max of two variables is cheaper than the square-root of one depends on implementation details, I guess?
You can also re-use the random variable that the max 'tossed' away by scaling it.
Whether taking the max of two variables is cheaper than the square-root of one depends on implementation details, I guess?
You can also re-use the random variable that the max 'tossed' away by scaling it.