f | def rnd(a, b=None): | f | def rnd(a, b=None): |
n | | n | import random |
| if b is None: | | if b is None: |
| match a: | | match a: |
n | case int(a): | n | case int(value): |
| return random.randint(0, a) | | return random.randint(0, value) |
| case str(a): | | case str(value): |
| return random.choice(a.split()) | | return random.choice(value.split()) |
| case list(a): | | case list(value): |
| return random.choice(a) | | return random.choice(value) |
| case _: | | case _: |
| return random.choice(list(a)) | | return random.choice(list(a)) |
| else: | | else: |
| match (a, b): | | match (a, b): |
t | case [int(a), int(b)]: | t | case [int(start), int(end)]: |
| return random.randint(a, b) | | return random.randint(start, end) |
| case [float(a), int(b) | float(b)]: | | case [float(start), int(end) | float(end)]: |
| return a + (b - a) * random.random() | | return start + (end - start) * random.random() |
| case [str(a), int(b)]: | | case [str(text), int(length)]: |
| start = random.randint(0, len(a) - b) | | idx = random.randint(0, len(text) - length) |
| return a[start:start + b] | | return text[idx:idx + length] |
| case [str(a), str(b)]: | | case [str(text), str(separator)]: |
| return random.choice(a.split(b)) | | return random.choice(text.split(separator)) |
| case [list(a), int()]: | | case [list(items), int(count)]: |
| return random.choices(a, k=b) | | return random.choices(items, k=count) |
| case [_, int(b)]: | | case [_, int(count)]: |
| return random.choices(list(a), k=b) | | return random.choices(list(a), k=count) |