Nodes/Quality of Life Nodes for ComfyUI/CSV Random Reader (Soze)
ComfyUI Node

CSV Random Reader (Soze)

Roll a random row from your prompt CSV, on demand

By SozeInc·Created 2 years ago·Updated 8 days ago· 10
CSV Random Reader (Soze)
    • Column_1
    • Column_2
    • Column_3
    • Column_4
    • Column_5
    • Column_6
    • Column_7
    • Column_8
    • Column_9
    • Column_10
    • First_Row_Line
    • Selected_Lines
    • Selected_Count
    • Total_Rows
    • status
    csv_filename_path
    num_rows1
    csv_text
    seed0
    allow_repeatsfalse
    skip_headerfalse

    Prompt iteration usually means a big spreadsheet and a counter, which is great when you want every row exactly once. Sometimes you want the opposite: a random subject, style or setting pulled from a list, every run, for the serendipity. CSV Random Reader is the node for that. It reaches into a CSV file - or inline CSV text - grabs N random rows, and hands you the cells as outputs ready to feed a prompt builder or an enum switch.

    It's the "lucky dip" sibling of the Soze pack's regular CSV Reader. Same CSV muscle, but instead of walking an index it rolls the dice.

    How it works

    Point it at a file via csv_filename_path (absolute path anywhere on disk, or a path relative to the pack's bundled py/csv_files folder), or paste CSV straight into csv_text - inline text always wins when it's non-empty. num_rows says how many rows to draw.

    The controls that matter:

    • seed - the one to learn first. 0 means nondeterministic: the node re-runs every prompt, so each run is a fresh draw. Any other value seeds the RNG and makes the pick reproducible and cacheable (same CSV, same seed, same rows every time). Great for "this exact random set, again."
    • allow_repeats - off by default, which uses unique sampling (clamped to the row count). On, and the same row can appear multiple times.
    • skip_header - treat the first row as a header and don't return it.

    Outputs are shaped for downstream text nodes: Column_1 through Column_10 (the first ten cells of the drawn row), plus First_Row_Line (the raw header row - useful when you have many columns and want to know what's what), Selected_Lines (all drawn rows as raw text), Selected_Count, Total_Rows, and status.

    Where it earns its keep

    Wire Column_1 into a prompt block and Column_2 into a sampler name feeding an Any Enum Switch, and you've got a random-prompt generator that's fully in-graph and versionable. Pair the seed output from a run with a fixed seed and you can replay a specific lucky draw. It's also just handy for QA: pull three random rows out of a 400-line prompt file to spot-check.

    Where people get burned: only ten columns get named outputs - a wide CSV with fifteen columns means columns 11–15 are reachable only through Selected_Lines. And if your "random" results look suspiciously familiar, check the seed - 0 is random, anything else is deliberately deterministic. File-encoding hiccups on odd CSVs are handled (UTF-8 with a Windows-1252 fallback), but keep files plain UTF-8 and you'll never think about it.

    Installing it

    Standard pack install:

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

    Or install "ComfyUI_Soze" via ComfyUI Manager and restart. No API keys, no model downloads - pure Python. It lives under the utils category as "CSV Random Reader (Soze)".

    Categoryutils

    Inputs (6)

    NameTypeDefaultDescription
    csv_filename_pathSTRINGAbsolute path or path relative to py/csv_files. Ignored if csv_text is non-empty.
    num_rowsINT11–10000How many rows to randomly pick.
    csv_textoptSTRINGInline CSV. Takes precedence over csv_filename_path when non-empty.
    seedoptINT00–184467440737095500000 = nondeterministic; any other value seeds the RNG for reproducible picks.
    allow_repeatsoptBOOLEANfalseIf True, the same row may be picked more than once when num_rows exceeds available rows.
    skip_headeroptBOOLEANfalseSkip the first row (treat it as a header).

    Outputs (15)

    NameTypeDescription
    Column_1STRING
    Column_2STRING
    Column_3STRING
    Column_4STRING
    Column_5STRING
    Column_6STRING
    Column_7STRING
    Column_8STRING
    Column_9STRING
    Column_10STRING
    First_Row_LineSTRING
    Selected_LinesSTRING
    Selected_CountINT
    Total_RowsINT
    statusSTRING