The BEST Way to Find a Random Point in a Circle | #SoME1 #3b1b
Video Statistics and Information
Channel: nubDotDev
Views: 86,383
Rating: 4.9321909 out of 5
Keywords: probability, pdf, cdf, random point, random point in a circle, random point in circle, summer of math exposition, SoME, SoME1, leetcode 478
Id: 4y_nmpv-9lI
Channel Id: undefined
Length: 18min 35sec (1115 seconds)
Published: Sat Aug 21 2021
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
Hey, I'm the creator of this video. Thank you so much for all the kind words! Also all the criticisms you've made are very helpful and informative!
Sometimes you can spot video games with "square" explosions presumably because particle velocities are chosen naively, something like:
And then there's the case of Williams Defender, with nice round explosions, and its sequel, Stargate, with inexplicable square explosions.
Very interesting video! I didn't know about two of these techniques.
Regarding the ending: Benchmarking numerical Python is always feels pointless. The slowest function run in any performance-oriented language implementation is going to beat the snot out of the fastest function in CPython. If you cared about performance, you wouldn't be using Python in the first place.
So here's my own benchmark in C:
circle.c
. The relative results are similar (Clang 12.0.1) where rejection sampling is the clear winner:Those transcendental functions are just so expensive. The latter three are far friendlier to a SIMD implementation, though: They have a fixed number of steps and no loop.
sum_dist
andmax_dist
would require masking for the branch, andsqrt_dist
is completely branchless. However, with rejection sampling at 4x faster in the straightforward case, a 4-lane wide SIMD of the others could only just match the speed of rejection sampling.Strange that randomly choosing a spoke length fails, but adding two random spoke lengths (and reflecting if necessary) gets past this problem. I definitely wouldn't have thought of this, and just used the cartesian method, or the (incorrect) spoke length and angle method.
Yep, rejection sampling is the easiest. When I worked on a raytracer, I needed a way to randomly sample from a unit sphere. Generalizing rejection sampling to 3d was the fastest and more correct way.
What a wonderful video, great use of Manim and great math being put to work.
Why are so many posters rushing to the comments to share the first half-formed thought that entered their brain after only reading the title.
This is a comment thread discussing a video. You should watch the video before commenting on it.
I really enjoyed the video and learned about inverse sampling, thanks!
Regarding the bit about
random() + random() =/= 2 * random().
One thing that adds to the confusion is the way they are written. It sort reads likex + x = 2x
when in reality this is not necessarily the case. If we would have writtenrand1 = random()
andrand2 = random()
then perhaps it would be easier to digest that in generalrand1 + rand2 =/= 2 * rand1
orrand1 + rand2 =/= 2 * rand2
.ITT "I didn't watch the video, but is this the solution?"