ComfyUI Node

pop random

Grab a random key-value pair out of a dict — reproducible when you want it

By StableLlama·Created about a year ago·Updated 4 days ago· 48
pop random
  • input_dict
  • dict
  • key
  • value
  • success
seed0

Sometimes you don't want the most recent entry in a dict, and you don't want to specify a key - you want to reach in blind and pull out some pair. That's what pop random (Basic data handling: DictPopRandom) is for. It removes a random key-value pair from a dictionary and hands you everything you need to use it.

Feed it one input, input_dict (a DICT - this pack's custom type, so it wires into other dict nodes from the same pack), and you get the same four outputs as its non-random sibling pop item:

  • dict - the dictionary minus the removed pair
  • key - the popped key as a STRING
  • value - the popped value (ANY)
  • success - BOOLEAN, False if the dict was empty

The seed input is the interesting part

There's one optional input, seed (INT, default 0). This is a standard ComfyUI seed widget with the "control_after_generate" randomize button, and it does two things. If you leave it randomizing, every run picks a different random pair - good for variety-driven workflows where you want to sample something new each time.

If you set it fixed to a number, the pick becomes reproducible. The node uses random.Random(seed), so the same seed over the same dict gives the same key every time. That's genuinely useful when you're debugging: a random failure that you can't reproduce is a nightmare, and pinning the seed turns it into a deterministic one. (The source even implements IS_CHANGED so the node recalculates whenever the seed changes - the machinery is there on purpose.)

Where this fits

This is a pick-a-random-item node that also removes what it picks. Use it for random selection without replacement from a pile of prompts, seeds, or paths. Like the rest of this pack's dict mods, it works on a copy - dict(input_dict) - so your original dict isn't mutated, which keeps workflows predictable.

One honest caveat about "random": Python's random.choice is uniform, but it's also not cryptographically random. That's fine here; you're picking a prompt to try, not rolling dice for security. Also note the empty-dict behavior mirrors pop item - no error, just key = "", value = None, success = False. Branch on success rather than letting a downstream node assume a value exists.

Installing it

This node is part of the Basic data handling pack by StableLlama. In ComfyUI Manager, search "Basic data handling" and install, then restart. Manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

then restart. No extra dependencies, no requirements.txt, no model downloads - the pack is pure Python with a declared empty dependency list.

Troubleshooting

If your "random" picks keep repeating, check the seed widget - it's probably stuck on a fixed value because you clicked it fixed and forgot. If success is always False, the dict is empty. And if you expected a reproducible pick but changed the dict's contents between runs, remember the seed only reproduces the index choice; a different dict gives a different result even with the same seed.

CategoryBasic/DICT

Inputs (2)

NameTypeDefaultDescription
input_dictDICT
seedoptINT00–18446744073709550000

Outputs (4)

NameTypeDescription
dictDICT
keySTRING
value*
successBOOLEAN