ComfyUI > Nodes > ComfyUI-LogicUtils > Weighted Random Choice

ComfyUI Node: Weighted Random Choice

Class Name

WeightedRandomChoice

Category
Logic Gates
Author
aria1th (Account age: 3016days)
Extension
ComfyUI-LogicUtils
Latest Updated
2026-01-21
Github Stars
0.1K

How to Install ComfyUI-LogicUtils

Install this extension via the ComfyUI Manager by searching for ComfyUI-LogicUtils
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-LogicUtils in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Weighted Random Choice Description

Selects items from a list based on weights, allowing controlled randomness with reproducible results.

Weighted Random Choice:

The WeightedRandomChoice node is designed to facilitate the selection of an item from a list based on specified weights, allowing for a probabilistic approach to decision-making. This node is particularly useful when you want to introduce randomness into your workflow but still maintain control over the likelihood of each item's selection. By assigning weights to each item, you can influence the probability of their selection, making it ideal for scenarios where certain outcomes are preferred over others. This node parses a specially formatted input string to determine the items and their respective weights, ensuring that the selection process is both flexible and customizable. The use of a seed for the random number generator ensures that the results can be reproduced, which is crucial for consistency in iterative processes.

Weighted Random Choice Input Parameters:

input_string

The input_string parameter is a string that contains the items and their associated weights, formatted as value|weight$value2|weight2.... This parameter is crucial as it defines the pool of items from which the node will make a selection. The weights determine the likelihood of each item being chosen, with higher weights increasing the probability. The default value is "apple|10$banana|1$orange|3", which means that apple is ten times more likely to be selected than banana, and over three times more likely than orange.

separator

The separator parameter specifies the character used to split the input_string into individual items and weights. This allows for flexibility in how the input string is structured, accommodating different formatting preferences. The default separator is "$", which is used to delineate different items and their weights within the input string.

seed

The seed parameter is an integer that initializes the random number generator, ensuring that the selection process can be replicated. By setting a specific seed, you can achieve consistent results across multiple runs, which is essential for debugging and iterative testing. The default value is 0, and it can range from 0 to 2**63-1.

Weighted Random Choice Output Parameters:

STRING

The output of the WeightedRandomChoice node is a single STRING, representing the item that was selected based on the weighted probabilities. This output is crucial as it reflects the result of the probabilistic selection process, providing a tangible outcome that can be used in subsequent steps of your workflow. The selected item is determined by the weights specified in the input string, ensuring that the output aligns with the intended probabilities.

Weighted Random Choice Usage Tips:

  • Ensure that the weights in your input_string are correctly formatted and reflect the desired probabilities for each item. This will help achieve the intended randomness in your selection process.
  • Use the seed parameter to maintain consistency across different runs, especially when testing or debugging your workflow. This will allow you to reproduce the same results and verify the behavior of the node.
  • Experiment with different separators if your input data is structured differently. This flexibility can help integrate the node into various workflows without needing to reformat your data.

Weighted Random Choice Common Errors and Solutions:

Invalid weight format

  • Explanation: This error occurs when the weight specified for an item cannot be converted to a float, possibly due to incorrect formatting or non-numeric characters.
  • Solution: Ensure that all weights in the input_string are valid numbers and correctly formatted. Double-check for any typos or misplaced characters.

Empty input string

  • Explanation: If the input_string is empty or improperly formatted, the node may not be able to parse any items or weights, leading to an error.
  • Solution: Verify that the input_string is not empty and follows the correct format of value|weight$value2|weight2.... Ensure that each item has an associated weight.

Separator not found

  • Explanation: This error can occur if the specified separator does not match the character used in the input_string, preventing the node from correctly splitting the items and weights.
  • Solution: Confirm that the separator matches the character used in your input_string to separate different items and weights. Adjust the separator if necessary.

Weighted Random Choice Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-LogicUtils
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.