I run your code, one thing, the xp and yp are same every time. should we use random seed(0) first? Perhaps; does this remark not apply to your original program, as well? What is the objection to starting with the same seed every time?
I do not know the purpose of your program, and my comments and suggestions were weighted towards the programming aspects, and to indicate how you could concentrate on your problem proper by leveraging available library routines.
In a program that uses pseudo-random numbers, it is useful to start out with code that generates the same sequence every time, which makes debugging easier, after which you can generate a seed using the system clock reading or something similar.