Random int and random float tools (#148)

As requested by D&D fans
This commit is contained in:
Eric Gustin 2024-11-06 09:28:05 -08:00 committed by GitHub
parent 311bfaa26f
commit 6d1bc6c084
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,36 @@
import random
from typing import Annotated, Optional
from arcade.sdk import tool
@tool
def generate_random_int(
min_value: Annotated[int, "The minimum value of the random integer"],
max_value: Annotated[int, "The maximum value of the random integer"],
seed: Annotated[
Optional[int],
"The seed for the random number generator. If None, the current system time is used.",
] = None,
) -> Annotated[int, "A random integer between min_value and max_value"]:
"""Generate a random integer between min_value and max_value (inclusive)."""
if seed is not None:
random.seed(seed)
return random.randint(min_value, max_value) # noqa: S311
@tool
def generate_random_float(
min_value: Annotated[float, "The minimum value of the random float"],
max_value: Annotated[float, "The maximum value of the random float"],
seed: Annotated[
Optional[int],
"The seed for the random number generator. If None, the current system time is used.",
] = None,
) -> Annotated[float, "A random float between min_value and max_value"]:
"""Generate a random float between min_value and max_value."""
if seed is not None:
random.seed(seed)
return random.uniform(min_value, max_value) # noqa: S311