Skip to content

Commit 6522c71

Browse files
feat(nodes): add RandomIntInvocation (#3390)
just outputs a single random int
2 parents e559730 + 9c1e65f commit 6522c71

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

invokeai/app/invocations/math.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Literal
44

55
from pydantic import BaseModel, Field
6+
import numpy as np
67

78
from .baseinvocation import BaseInvocation, BaseInvocationOutput, InvocationContext, InvocationConfig
89

@@ -73,3 +74,12 @@ class DivideInvocation(BaseInvocation, MathInvocationConfig):
7374

7475
def invoke(self, context: InvocationContext) -> IntOutput:
7576
return IntOutput(a=int(self.a / self.b))
77+
78+
79+
class RandomIntInvocation(BaseInvocation):
80+
"""Outputs a single random integer."""
81+
#fmt: off
82+
type: Literal["rand_int"] = "rand_int"
83+
#fmt: on
84+
def invoke(self, context: InvocationContext) -> IntOutput:
85+
return IntOutput(a=np.random.randint(0, np.iinfo(np.int32).max))

0 commit comments

Comments
 (0)