From 5401f0bfa287b8f2237e55704f156671329bec78 Mon Sep 17 00:00:00 2001 From: Skullheadx <704277@pdsb.net> Date: Tue, 27 Dec 2022 19:37:09 -0500 Subject: [PATCH] fix glitch where 2 points on same spot --- graph.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/graph.py b/graph.py index d30f652..7fab2f5 100644 --- a/graph.py +++ b/graph.py @@ -9,11 +9,16 @@ def prune_filename(filename: str) -> int: def create(path: str, width: int, height: int, nodes: int): graph = [] text = f"{width} {height} {nodes}\n" + seen = set() # so that there are no duplicate points - for node in range(nodes): + counter = 0 + while counter < nodes: x, y = (random.randint(0, width), random.randint(0, height)) - graph.append((x, y)) - text += f"{x} {y}\n" + if (x, y) not in seen: + graph.append((x, y)) + text += f"{x} {y}\n" + seen.add((x, y)) + counter += 1 current_file = 0 for root, dirs, files in os.walk(path): -- 2.54.0