ComfyUI Node Runs on cloud

GetRandomFile

A seeded dice roll that returns a file path β€” for random references and more

By edenartlabΒ·Created 3 years agoΒ·Updated 6 months agoΒ· 119
GetRandomFile
    • STRING
    β—„folder.β–Ί
    β—„seed0β–Ί

    GetRandomFile does one thing: pick a random file from a folder and hand you back its full path as a string. No image loading, no filtering by type, no sorting - just random.choice() over the directory listing, seeded so you can reproduce the pick. The power is in how you use that path.

    It's part of eden_comfy_pipelines, Eden.art's 70+ node suite.

    The two inputs

    • folder - the directory to pick from, default . (the current working directory - you'll almost always want to type a real path). Only files directly in the folder count; no recursion.
    • seed - an INT from 0 to 100000. Same seed + same folder contents = same file, every time. This is the node's best feature.

    One output, STRING, the absolute path of the chosen file.

    How the seeding actually works

    The mechanism is worth understanding because it affects everything downstream: the node calls random.seed(seed) and then random.choice(files). Python's random module is a global, deterministic PRNG, so two things follow. First, given the same seed and the same folder listing order, you get the same file - that's the reproducibility you want. Second, the choice depends on the order os.listdir returns, which can differ between OSes or when files are added or removed. Add a file to the folder and a previously "same seed, same pick" run can now pick differently. So: it's reproducible for a fixed folder, not a stable hash of the folder. For a stable per-file identity, pair it with Eden_StringHash instead.

    What it's actually good for

    • Random reference images: pick a path, feed it to a LoadImage node, and every run starts from a different reference. Great for inspiration-batching.
    • Seeded variety: wire the seed from your main Eden_Seed and the random pick becomes part of your workflow's "one number to reroll everything" pattern.
    • Prompt roulette: point it at a folder of .txt prompt files, feed the path into a text loader, and you've got a random-prompt generator for basically free.

    Because it returns a bare path rather than an image, it composes with anything that accepts a path - which is most loaders in the ecosystem. It also doesn't care what kind of file it picks, so if your folder mixes images and prompts, it'll happily land on either; keep single-type folders if that matters.

    The honest limits

    No recursion, no extension filter, no "most recent" logic - if you need those, the pack's ImageFolderIterator or Get_Prefixed_Imgs cover different ground. And the seed cap at 100000 is low if you're trying to explore a huge random space; for batch variation, drive it from a counter or hash rather than a manual widget.

    Installing it

    Standard pack install - ComfyUI Manager (search "eden"), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/edenartlab/eden_comfy_pipelines.git
    cd eden_comfy_pipelines
    pip install -r requirements.txt
    

    Restart ComfyUI. Zero dependencies, zero downloads - it's a dice roll that returns a string, and once you start wiring it into loaders you'll find a dozen uses for it.

    CategoryEden 🌱

    Inputs (2)

    NameTypeDefaultDescription
    folderSTRING.β€”
    seedINT00–100000β€”

    Outputs (1)

    NameTypeDescription
    STRINGSTRINGβ€”