random numer generation except inside of the circle in python

Issue

I want to generate 750 random number in 2D data x (0,1) and y (0,1)

X1 = np.random.random((750,2))

However, I want to make sure I don’t have any value in the circular region such as

enter image description here

I can remove the value, but I want to fix the number of the random number to be 750. What would be the best way to generate such list?

Solution

import random
points = []
radius = 1
num_points=1500
index = 0
max_coord = 750
while index < num_points:
  x=random.random()*max_coord
  y=random.random()*max_coord
  if x**2 + y**2 > radius**2:
    points = points + [[x,y]]
    index = index + 1
print(points)

Change max_coor to obtain bigger numbers. This only gives you 1500 points outside the circle of the given radius=1. Each coordinate varies between 0 and 750

Answered By – hjbello

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.