Define a bijective mapping from a square to a circle I recently ran into a computer science problem that asked to uniformly generate random points within a circle. There's numerous algorithmatic ways to achieve this, but I'm interested in some form of a mapping.
My idea is, since generating uniform random points within a square is easy, can one explicitly define a bijective mapping from a square to a circle? (Or any shape to a circle). 
If yes, what would be the mapping? Is it linear? And how would one go about defining these explicit mappings in the general case; i.e. given a domain subspace and a codomain subspace, how can one arithmetically find a mapping beyond just "looking at it"? 
EDIT: Overlooked issue is, of course, the distribution in the circle also needs to be uniform
 A: Given a point $(x,y)$ chosen uniformly at random on the unit square, take $r = \sqrt x$ and $\theta = 2\pi y$. Going backwards, given $(r,\theta)$, take $x = r^2$ and $y = \frac\theta{2\pi}$.
A: There are different ways you can do this. Firstly the problem with a bijection is that it won't necessarily preserve the uniform distribution. Anyway, here's my approach that came to mind first.


*

*Probably the easiest approach is restricting the square. It's not a bijection, it's just the identity map $Id:\bigcirc\rightarrow\square$. You then consider $Id^{-1}(\square)$


Start by generating a collection of points randomly on a square. Then you check to see if the point lies in the circle - if it does, you keep it. If it doesn't, you discard it. More specifically, let's say you randomly generate points in a $1\times 1$ square centred at $(0,0)$. Then you randomly generate points $\{a_1,a_2,a_3,...\}$. Each $a_i$ is of the form $a_i = (x_i, y_i)$. Now you know that $a_i$ lies in the circle only if $x_i^2+y_i^2 < r^2 = 1/4$. So your code will look like:


*

*Generate a set of points randomly in a $1\times 1$ square.

*For each point $(x_i,y_i)$, compute $x_i^2+y_i^2$.

*If $x_i^2+y_i^2 < 1/4$, add $(x_i,y_i)$ to a new set, which corresponds to points radnomly generated by a uniform distribution on the circle.


You know this "map" doesn't interfere with the distribution because it's just the restriction of a square onto the circle.
