Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#JavaScript, 75 bytes
Rejection-based:
do x=(r=()=>4*Math.random()-2)(),y=r() while(x*x+y*y>1) alert(`(${[x,y]})`)
Direct method (80 bytes):
alert(`(${[(z=(m=Math).sqrt((r=m.random)()))*m.sin(p=m.PI*2*r()),z*m.cos(p)]})`)
Direct method (8180 bytes):
alert(`(${[(z=(m=Math).sqrt((r=m.random)()))*m.sin(p=m.PI*2*r()),z*m.cos(p)]})`);
Direct method (81 bytes):
Rejection-basedDirect method (81 bytes): chooses random points in the unit square, and rejects those outside the disc.
Rejection-based: chooses random points in the unit square, and rejects those outside the disc.