feat(nodes): add RandomIntInvocation

just outputs a single random int
This commit is contained in:
psychedelicious 2023-05-11 20:31:48 +10:00
parent 4333852c37
commit 483f2ccb56

View File

@ -3,6 +3,9 @@
from typing import Literal
from pydantic import BaseModel, Field
import numpy as np
from invokeai.app.util.misc import get_random_seed
from .baseinvocation import BaseInvocation, BaseInvocationOutput, InvocationContext, InvocationConfig
@ -73,3 +76,12 @@ class DivideInvocation(BaseInvocation, MathInvocationConfig):
def invoke(self, context: InvocationContext) -> IntOutput:
return IntOutput(a=int(self.a / self.b))
class RandomIntInvocation(BaseInvocation):
"""Outputs a single random integer."""
#fmt: off
type: Literal["rand_int"] = "rand_int"
#fmt: on
def invoke(self, context: InvocationContext) -> IntOutput:
return IntOutput(a=np.random.randint(0, np.iinfo(np.int32).max))