f | import random | f | import random |
| from collections.abc import Sequence, Iterable | | from collections.abc import Sequence, Iterable |
| | | |
| def rnd(a, b=None): | | def rnd(a, b=None): |
n | match [a, b]: | n | match (a, b): |
| case [int(), None]: | | case [int(), None]: |
| return random.randint(0, a) | | return random.randint(0, a) |
| case [int(), int()]: | | case [int(), int()]: |
| return random.randint(a, b) | | return random.randint(a, b) |
| case [float(), int() | float()]: | | case [float(), int() | float()]: |
| return a + (b - a) * random.random() | | return a + (b - a) * random.random() |
| case [str(), int()]: | | case [str(), int()]: |
n | start_idx = random.randint(0, len(a) - b) | n | idx = random.randint(0, len(a) - b) |
| return a[start_idx:start_idx + b] | | return a[idx:idx + b] |
| case [str(), None]: | | case [str(), None]: |
| return random.choice(a.split()) | | return random.choice(a.split()) |
| case [str(), str()]: | | case [str(), str()]: |
| return random.choice(a.split(b)) | | return random.choice(a.split(b)) |
| case [Sequence() | Iterable(), None]: | | case [Sequence() | Iterable(), None]: |
n | return random.choice(list(a)) | n | return random.choice(tuple(a)) |
| case [Sequence() | Iterable(), int()]: | | case [Sequence() | Iterable(), int()]: |
t | return random.choices(list(a), k=b) | t | return random.choices(tuple(a), k=b) |