Skip to content

Enhance random_seed() in math_utils.py to generate high-entropy integers #77

Description

@gilkazi

Currently, random_seed() returns -1, passing the fallback randomization duty to the stable-diffusion.cpp binary. The C++ backend utilizes system clock cycles that frequently generate lower-entropy seeds under 100,000.

For modern low-step distillation samplers (LCM, DMD2), low-entropy/short seeds generate flatter, less vibrant noise maps, leading to a noticeable loss in structural detail over 4-8 steps.

The Fix: Generate a 9-digit high-entropy integer directly via Python's random module on the frontend before passing it down.

in modules/utils/math_utils.py

def random_seed():
"""Generates a high-entropy 9-digit seed to bypass low-precision C++ clock limits"""
# Generates a random number between 100,000,000 and 999,999,999
high_entropy_seed = random.randint(100000000, 999999999)
return gr.update(value=high_entropy_seed)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions