Execution of while loop - iteration times vary hugely , or the loop gets stuck...

My code generates two types of random points within a circle (which is divided into 3 regions), and calculates distances between them. There are certain constraints on the minimum distance between these two types of random points - u and R, executed usingwhile true . The problem is that it gets stuck on certain iterations where the execution takes quite long time - sometimes few minutes ( or gets stuck?),whereas other iterations are running in a very short time (on average around 0.1s). This means something is wrong with the code, but I cannot figure out what it is...Hence, I would greatly appreciate help on this.

In the first part of the code, I generate R points (10 of them per per a region of circle), and that runs fine. The problem is with the second part, where I generateu points (2 u points per each R point, and they are within a certain distance ofR points). There, I compute the distance of eachu point with (0,0) and with all other previously generated R points. The code for the second part is given below. distance is just a function calculating the distance between the two points with x and y coordinates.