3 ms·
The easiest way I know how to do it, call rand 3 times: you get a cube -> Calculate the length of the vertex if outside of the sphere reject the sample -> Norma
by Qantourisc 12y ago
The easiest way I know how to do it, call rand 3 times: you get a cube -> Calculate the length of the vertex if outside of the sphere reject the sample -> Normalize. IIRC this should be well distributed, yet not fast.
- ColinWright 12y agoAnd in higher dimensions, extremely slow, as the volume of the sphere fairly rapidly approaches zero, so nearly all your points are outside. You need to work harder than that, as most of the other comments are pointing out.
- im3w1l 12y agoIs the rejection method better at low dimensions? If so, where does the gaussian method catch up?
- ColinWright 12y agoIn even dimensions, volume of a sphere of radius 1 is: V_{2k} = pi^k/k! For 10 dimensions, the hypersphere is of volume 2.55, but the enclosing box is of volume 2^10 = 1024. So roughly one in 400 trials gets you a point inside the sphere. Not good odds.
- Qantourisc 12y agoThe rejection method is never better I think, work smarter not harder. But it's an easy way to remember and do it. Don't recommend using it when you any actual performance. In terms of CPU power, calculating the length of the vector and doing a branch, I think, is going to be slower then the proper way to do it.