News for hackers. Stuff that matters.
Re:Uniformly Sample Points in a Disk by olliej on Thursday May 26, 2022 @01:36PM (#31521180)
Sqrt is actually one of the faster operations, though obviously avoiding the need for any operation is clearly preferable :)
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.