News for hackers. Stuff that matters.
Re:Uniformly Sample Points in a Disk by eru on Thursday May 26, 2022 @01:55AM (#31515121)
> and graphics people are so insane about perf, they arent going to just start doing sqrt over and over. they are going to rejection sample anyway because it just 2 fmas

If you can re-jig the rest of your algorithm to consume the square of the radius (instead of the radius itself), you don't need to take a square-root here.

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.