Skip to content

🎲 CR Random Multiline Values

Documentation

  • Class name: CR Random Multiline Values
  • Category: 🧩 Comfyroll Studio/🛠️ Utils/🎲 Random
  • Output node: False

This node generates a multiline string composed of randomly selected characters or digits based on a specified value type. It allows for the creation of diverse patterns such as binary, decimal, natural numbers, hexadecimal, alphabetic, alphanumeric, or custom-defined sequences. The randomness can be controlled with a seed value, and the node supports customization of the output through parameters like row count, string length, and optional prepended text.

Input types

Required

  • seed
    • A value used to initialize the random number generator, ensuring reproducibility of the random patterns generated by the node.
    • Comfy dtype: INT
    • Python dtype: int
  • value_type
    • Specifies the type of characters or digits to be used in generating the multiline string. It determines the character set from which random selections are made, influencing the pattern and appearance of the output.
    • Comfy dtype: COMBO[STRING]
    • Python dtype: str
  • rows
    • Determines the number of lines in the generated multiline string. Each line is composed of randomly selected characters or digits based on the specified value type.
    • Comfy dtype: INT
    • Python dtype: int
  • string_length
    • Specifies the length of each line in the multiline string, controlling how many characters or digits are randomly selected and concatenated per line.
    • Comfy dtype: INT
    • Python dtype: int
  • custom_values
    • Allows for the specification of a custom set of characters or digits from which the random selections are made, enabling highly customized and unique patterns.
    • Comfy dtype: STRING
    • Python dtype: str
  • prepend_text
    • An optional text to be prepended to each line of the generated multiline string, allowing for additional customization of the output.
    • Comfy dtype: STRING
    • Python dtype: str

Output types

  • multiline_text
    • Comfy dtype: *
    • The generated multiline string composed of randomly selected characters or digits, arranged according to the specified parameters.
    • Python dtype: str
  • show_help
    • Comfy dtype: STRING
    • A URL providing access to further documentation and help related to the node's functionality.
    • Python dtype: str

Usage tips

Source code

class CR_RandomMultilineValues:

    @classmethod
    def INPUT_TYPES(cls):

        types = ["binary", "decimal", "natural", "hexadecimal", "alphabetic", "alphanumeric", "custom"]

        return {"required": {"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
                             "value_type": (types,),
                             "rows": ("INT", {"default": 5, "min": 1, "max": 2048}),
                             "string_length": ("INT", {"default": 5, "min": 1, "max": 1024}),
                             "custom_values": ("STRING", {"multiline": False, "default": "123ABC"}),
                             "prepend_text": ("STRING", {"multiline": False, "default": ""}),
               }
        }

    RETURN_TYPES = (any_type, "STRING", )
    RETURN_NAMES = ("multiline_text", "show_help", )
    FUNCTION = "generate"
    CATEGORY = icons.get("Comfyroll/Utils/Random")

    def generate(self, value_type, rows, string_length, custom_values, seed, prepend_text):

        show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-random-multiline-values"

        # Set the seed
        random.seed(seed)

        if value_type == "binary":
            choice_str = '01'
        elif value_type == "decimal":
            choice_str = '0123456789'
        elif value_type == "natural":
            choice_str = '123456789'             
        elif value_type == "hexadecimal":
            choice_str = '0123456789ABCDEF'       
        elif value_type == "alphabetic":
            choice_str = string.ascii_letters
        elif value_type == "alphanumeric":
            choice_str = string.ascii_letters + string.digits           
        elif value_type == "custom":
            choice_str = custom_values
        else:
            pass

        multiline_text = '\n'.join([prepend_text + ''.join(random.choice(choice_str) for _ in range(string_length)) for _ in range(rows)]) 

        return (multiline_text, show_help, )