Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add 'Random Float' node <3 #4581

Merged
merged 8 commits into from
Sep 26, 2023
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions invokeai/app/invocations/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ def invoke(self, context: InvocationContext) -> IntegerOutput:
return IntegerOutput(value=np.random.randint(self.low, self.high))


@invocation("rand_float",title="Random Float",tags=["math","float","random"],category="math",version="1.0.0")
class RandomFloatInvocation(BaseInvocation):
"""Output a random value between min and max"""

min: float = InputField(default=0.0, description="The mimimum returned value")
max: float = InputField(default=1.0, description="The maximum returned value")
decimals: int = InputField(default=2, description="The number of decimal places in the generated float")

def invoke(self, context:InvocationContext) -> FloatOutput:
random_float = np.random.uniform(self.min, self.max)
rounded_float = round(random_float, self.decimals)
return FloatOutput(value=rounded_float)


@invocation(
"float_to_int",
title="Float To Integer",
Expand Down