From 2661be74ba9431ac5aabce598c3fd44e1f83d6a0 Mon Sep 17 00:00:00 2001 From: Nazmul Haque Naqib <39087050+nokibsarkar@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:14:41 +0600 Subject: [PATCH] Make deterministic for pre-3.7 This uses a iterator method for performance boost. Resolves #15 --- randomcolor/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/randomcolor/__init__.py b/randomcolor/__init__.py index 51f55c1..fb93b0d 100644 --- a/randomcolor/__init__.py +++ b/randomcolor/__init__.py @@ -13,8 +13,10 @@ def __init__(self, seed=None): self.colormap = json.load(fh) self.random = random.Random(seed) + sorted_color_names = sorted(self.colormap.keys()) - for color_name, color_attrs in self.colormap.items(): + for color_name in sorted_color_names: + color_attrs = self.colormap[color_name] lower_bounds = color_attrs['lower_bounds'] s_min = lower_bounds[0][0] s_max = lower_bounds[len(lower_bounds) - 1][0]