-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathrandom_line_from_input.py
More file actions
34 lines (26 loc) · 878 Bytes
/
random_line_from_input.py
File metadata and controls
34 lines (26 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
class RandomLineFromInput:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"forceInput": True}),
"seed": ("INT", {"default": 1}),
},
}
RETURN_TYPES = ("STRING",)
FUNCTION = "random_line"
OUTPUT_IS_LIST = (False,)
CATEGORY = "Bjornulf"
def random_line(self, text, seed):
random.seed(seed)
# Split the input text into lines
lines = text.split('\n')
# Remove empty lines and strip whitespace
lines = [line.strip() for line in lines if line.strip()]
if not lines:
return ([""],)
# Select a random line
chosen_line = random.choice(lines)
# Return as a list with one element
return (chosen_line,)