title: I have 100 points and using the distance function I wanted to look for the shortest path
body: <pre><code>import random
  
  radius = 200
  rangeX = (0, 2500)
  rangeY = (0, 2500)
  qty = 100  
  
  
  s = set()
  for x in range(-radius, radius+1):
      for y in range(-radius, radius+1):
          if x*x + y*y &lt;= radius*radius:
              s.add((x,y))
  
  rp = []
  excluded = set()
  
  i = 0
  
  while i&lt;qty:
      x = random.randrange(*rangeX)
      y = random.randrange(*rangeY)
      if (x,y) in excluded: 
          continue
  
      rp.append((x,y))
  
      i += 1
  
      excluded.update((x+dx, y+dy) for (dx,dy) in s)
  #This is to find 100 random points based on the range and the radius
  
  
  import math
  
  points = rp
  
  
  paths = ((0, 1, 2, 3), (0, 1, 3, 2), (0, 2, 1, 3), (0,2, 3, 1), (0, 3, 1, 2), (0, 3, 2, 1))
  
  def dist(p1, p2):
      return math.sqrt((p2[0]-p1[0])**2 + (p2[1]p1[1])**2)
  
  distances = []
  
  
  for path in paths:
  distances.append(dist(points[path[0]], points[path[1]]) +
                   dist(points[path[1]], points[path[2]]) +
                   dist(points[path[2]], points[path[3]]) +
                   dist(points[path[3]], points[path[0]]))
  
  
  print(f&quot;the shortest path is {min(distances):.2f} cm and the longest path is {max(distances):.2f} cm&quot;)
  #this allows the points from the 100 random points function to passed it going through the equation
  </code></pre>
  <p>So far I have encountered a few problems, the time it took to run the 100 points code is long which makes the code inefficient, and I also need a way to let me know what route &quot;all the points that make up the shortest path&quot;  allows the distance to be the shortest instead of just showing me the shortest path.</p>
  <p>Thank you in advance for your help.</p>