f | import random | f | import random |
| from collections.abc import Sequence, Iterable | | from collections.abc import Sequence, Iterable |
| | | |
n | def rnd(x, y=None): | n | def rnd(a, b=None): |
| match (x, y): | | match (a, b): |
| case [int(), int()]: | | case [int(), int()]: |
n | return random.randint(x, y) | n | return random.randint(a, b) |
| case [int(), None]: | | case [int(), None]: |
n | return random.randint(0, x) | n | return random.randint(0, a) |
| case [float(), _] | [_, float()]: | | case [float(), _] | [_, float()]: |
n | return x + (y - x) * random.random() | n | return a + (b - a) * random.random() |
| case [str(), int()]: | | case [str(), int()]: |
n | z = random.randint(0, len(x) - y) | n | start = random.randint(0, len(a) - b) |
| return x[z:z + y] | | return a[start:start + b] |
| case [str(), str()]: | | case [str(), str()]: |
n | return random.choice(x.split(y)) | n | return random.choice(a.split(b)) |
| case [str(), None]: | | case [str(), None]: |
t | return random.choice(x.split()) | t | return random.choice(a.split()) |
| case _ if isinstance(x, (Sequence, Iterable)) and isinstance(y, | | case _ if isinstance(a, (Sequence, Iterable)) and isinstance(b, |
| int): | | int): |
| return random.choices(list(x), k=y) | | return random.choices(list(a), k=b) |
| case _ if isinstance(x, (Sequence, Iterable)): | | case _ if isinstance(a, (Sequence, Iterable)): |
| return random.choice(list(x)) | | return random.choice(list(a)) |