29 lines
883 B
Python
29 lines
883 B
Python
import random
|
|
|
|
|
|
class Shortcode():
|
|
|
|
def __init__(self, Unprompted):
|
|
self.Unprompted = Unprompted
|
|
self.description = "Returns a random number between 0 and a given max value (inclusive)"
|
|
|
|
def run_atomic(self, pargs, kwargs, context):
|
|
_min = 0
|
|
if ("_min" in kwargs):
|
|
_min = self.Unprompted.parse_advanced(kwargs["_min"], context)
|
|
_max = self.Unprompted.parse_advanced(kwargs["_max"], context)
|
|
else:
|
|
_max = self.Unprompted.parse_advanced(pargs[0], context)
|
|
|
|
if ("_float" in pargs):
|
|
return (random.uniform(float(_min), float(_max)))
|
|
else:
|
|
return (random.randint(int(_min), int(_max)))
|
|
|
|
def ui(self, gr):
|
|
return [
|
|
gr.Number(label="Minimum number 🡢 _min", value=0, interactive=True),
|
|
gr.Number(label="Maximum number 🡢 _max", value=10, interactive=True),
|
|
gr.Checkbox(label="Evaluate as floats instead of integers 🡢 _float"),
|
|
]
|