|
|
|
|
|
by chmod775
499 days ago
|
|
Isn't there a likely faster analytical solution? At least I think sqrt, sin, and cos are generally considered to be slow. Maybe this: 1. Generate random X [-1 to 1] 2. Based on X you can calculate a range of legal Y that will still fall within the circle. Try to use a lookup table+interpolation with desired resolution to make this really fast if there's not some sufficiently fast hardware instructions we can abuse. 3. Generate random Y in that range. |
|
Yup, that calculation is called sqrt(1 - x²).
> Try to use a lookup table+interpolation with desired resolution to make this really fast
On modern hardware (like, most architectures from 1995-ish onwards), LUTs are mostly slower than polynomial-based solutions for the same level of accuracy.
> 1. Generate random X [-1 to 1]
As others have pointed out, this is already wrong unless you intend to reject some of the solutions later.