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