I am trying generate a random number that is within an annulus, i.e. we have a max and min radius. I tried doing:
while True:
x=random.uniform(-maxR, maxR)
y=random.uniform(-maxR, maxR)
R=math.sqrt(x**2 + y**2)
if R <= maxRadius and R >= minRadius:
if x>= -maxRadius and x <= maxRadius and x<=-minRadius and x>= minRadius:
print "passed x"
if y>= -maxRadius and y <= maxRadius and y<=-minRadius and y>= minRadius:
break
But this is very slow. Is it possible to feed more contraints into random.uniform
or is there another method?