Nodes/AUN ComfyUI Nodes/Random Text Index Switch V2
ComfyUI Node

Random Text Index Switch V2

Prompt roulette with a label you can actually use

By loz2754·Created 8 months ago·Updated about 24 hours ago· 5
Random Text Index Switch V2
    • text
    • label
    • index
    • prefixed_label
    minimum1
    maximum10
    modeRandom
    select1
    range1,2,5-8,12
    visible_inputs20
    text1
    text2
    text3
    text4
    text5
    text6
    text7
    text8
    text9
    text10
    text11
    text12
    text13
    text14
    text15
    text16
    text17
    text18
    text19
    text20

    This is the "one node instead of two" prompt randomizer, in the same spirit as Text Index Switch 4 - index generation and text selection fused together - but with an extra output that makes it genuinely better for building automated pipelines. The V2 suffix here buys you a prefixed_label: an index-and-name string like 3-cinematic that drops straight into filenames. If you're batch-generating and want each output to tell you which prompt produced it, that's the whole ballgame.

    What it does

    You give it up to 20 text inputs, pick a mode, and it generates an index then outputs the matching text. The four modes cover the usual ground:

    • Select - fixed index from the select widget.
    • Increment - cycles through minimummaximum, stepping each run. Perfect for turning a batch of prompts into one run per prompt, in order.
    • Random - uniform random within the range. The "surprise me" mode.
    • Range - picks from an explicit list like 1,2,5-8,12, cycling through it.

    Inputs and outputs

    Required: minimum, maximum (the inclusive bounds, clamped to your visible inputs), mode, select (the fixed index), range (the Range-mode list), and visible_inputs (2–20 sockets shown - hide the ones you're not using). Optional: text1text20, which is what you actually wire your prompts into.

    Outputs, and this is where it gets interesting:

    • text - the selected prompt. Wire into CLIP Text Encode.
    • label - the selected slot's label (the connected node's title, or "Text N").
    • index - the active index, for chaining into other nodes.
    • prefixed_label - the V2 addition: index-label, e.g. 3-cinematic. This is built for filenames. Feed it into a save node's template and every output file tells you at a glance which prompt made it.

    How it works

    Each run, the node clamps the range to your visible input count, generates the index per mode, then pulls the matching text. It reads the workflow data to find the title of the node connected to the selected slot - that's your label. The prefixed_label just strips any numeric prefix off the source title and prepends the index, so it stays clean even if your prompt node is itself named "3-cinematic".

    Two implementation details matter in practice. First, in Random/Increment/Range modes the node forces re-execution every run, so ComfyUI's caching can't freeze your random prompt on the first value - the classic bug that makes people think the node is broken. Second, it records its state (mode, index, selected text) into the workflow's metadata, which is useful when you're auditing what actually ran.

    V1 vs V2

    The original AUNRandomTextIndexSwitch has the same modes and outputs text, label, and index. V2 adds the prefixed_label output. That's the entire difference, and it's a meaningful one if you care about filenames - which, if you're batch-generating prompts, you absolutely should.

    Installing

    It ships in the AUN ComfyUI Nodes pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/loz2754/AUN-ComfyUI-Nodes
    

    Restart ComfyUI, or use ComfyUI Manager (search "AUN"). No models, no heavy deps beyond the pack standard, which Manager installs or you add via pip install -r custom_nodes/AUN-ComfyUI-Nodes/requirements.txt.

    The only habit worth building: rename the nodes feeding your slots, because the label and prefixed_label outputs are only as good as those titles. Do that once and this becomes the quiet workhorse of your batch-prompt workflows.

    CategoryAUN Nodes/Prompts

    Inputs (26)

    NameTypeDefaultDescription
    minimumINT11–20The minimum index for selection (inclusive).
    maximumINT101–20The maximum index for selection (inclusive).
    modeCOMBORandomSelect mode: Select for fixed index, Increment for cycling through range, Random for random index within range, Range for selecting a range of indices.
    selectINT11–20The fixed index value to output when in 'Select' mode.
    rangeSTRING1,2,5-8,12A comma-separated list of indices or ranges to select from in 'Range' mode (e.g. 1, 2, 5-8, 12).
    visible_inputsINT202–20How many text input sockets to expose on the node (2-20).
    text1optSTRINGText input 1. Only the selected index is output.
    text2optSTRINGText input 2. Only the selected index is output.
    text3optSTRINGText input 3. Only the selected index is output.
    text4optSTRINGText input 4. Only the selected index is output.
    text5optSTRINGText input 5. Only the selected index is output.
    text6optSTRINGText input 6. Only the selected index is output.
    text7optSTRINGText input 7. Only the selected index is output.
    text8optSTRINGText input 8. Only the selected index is output.
    text9optSTRINGText input 9. Only the selected index is output.
    text10optSTRINGText input 10. Only the selected index is output.
    text11optSTRINGText input 11. Only the selected index is output.
    text12optSTRINGText input 12. Only the selected index is output.
    text13optSTRINGText input 13. Only the selected index is output.
    text14optSTRINGText input 14. Only the selected index is output.
    text15optSTRINGText input 15. Only the selected index is output.
    text16optSTRINGText input 16. Only the selected index is output.
    text17optSTRINGText input 17. Only the selected index is output.
    text18optSTRINGText input 18. Only the selected index is output.
    text19optSTRINGText input 19. Only the selected index is output.
    text20optSTRINGText input 20. Only the selected index is output.

    Outputs (4)

    NameTypeDescription
    textSTRING
    labelSTRING
    indexINT
    prefixed_labelSTRING