From ea87f72a8aba6575d615119031757af13d0433b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8B=E3=81=BF=E3=81=AA=E3=83=BC=E5=85=88=E7=94=9F?= Date: Wed, 13 May 2026 19:57:09 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B9=B1=E6=95=B0=E7=94=9F=E6=88=90=E3=81=AE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=82=92random=E3=81=8B=E3=82=89secrets?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4=E3=81=97=E3=80=81=E3=83=A9=E3=83=B3?= =?UTF-8?q?=E3=83=80=E3=83=A0=E6=80=A7=E3=82=92=E5=90=91=E4=B8=8A=E3=81=95?= =?UTF-8?q?=E3=81=9B=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82=E3=81=BE=E3=81=9F?= =?UTF-8?q?=E3=80=81=E7=8A=B6=E6=85=8B=E7=AE=A1=E7=90=86=E3=81=AE=E3=82=BF?= =?UTF-8?q?=E3=82=A4=E3=83=A0=E3=82=B9=E3=82=BF=E3=83=B3=E3=83=97=E3=82=92?= =?UTF-8?q?time.time=5Fns()=E3=81=AB=E6=9B=B4=E6=96=B0=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot --- nodes.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/nodes.py b/nodes.py index 751e742..537acdf 100644 --- a/nodes.py +++ b/nodes.py @@ -1,14 +1,15 @@ import hashlib -import random import re +import secrets import threading +import time from aiohttp import web import folder_paths from server import PromptServer - +_RNG = secrets.SystemRandom() _STATES = {} _STATE_LOCK = threading.Lock() @@ -63,15 +64,15 @@ def _make_shuffle_order(count, first_index=None, previous_index=None): if first_index is not None: first_index = _clamp_index(first_index, count) rest = [index for index in indices if index != first_index] - random.shuffle(rest) + _RNG.shuffle(rest) return [first_index] + rest - random.shuffle(indices) + _RNG.shuffle(indices) # Avoid repeating the last item of the previous cycle as the first item # of the next cycle when possible. if count > 1 and previous_index is not None and indices and indices[0] == previous_index: - swap_index = random.randrange(1, count) + swap_index = _RNG.randrange(1, count) indices[0], indices[swap_index] = indices[swap_index], indices[0] return indices @@ -181,7 +182,7 @@ def _advance_state(state, checkpoints, mode): return if mode == "randomize": - state["current_index"] = random.randrange(count) + state["current_index"] = _RNG.randrange(count) return if mode == "shuffle_once": @@ -239,7 +240,7 @@ class CheckpointNameCycler: @classmethod def IS_CHANGED(cls, **kwargs): # This node is stateful and must run every queued execution. - return float("NaN") + return time.time_ns() def cycle(self, start_checkpoint, mode, change_every, unique_id=None): checkpoints = _get_checkpoints()