f | from collections.abc import Sequence, Iterable | f | from collections.abc import Sequence, Iterable |
| | | |
| def rnd(a, b=None): | | def rnd(a, b=None): |
| match (a, b): | | 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) |
n | case [float(), int() | float()]: | n | case [float(), float() | int()]: |
| return random.random() * (b - a) + a | | return random.random() * (b - a) + a |
| case [str(), int()]: | | case [str(), int()]: |
n | num = random.randint(0, len(a) - b) | n | start = random.randint(0, len(a) - b) |
| return a[num:num + b] | | return a[start:start + b] |
| case [str(), None]: | | case [str(), None]: |
t | return random.choice(a.split()) | t | return random.choice(a.split(' ')) |
| case [str(), str()]: | | case [str(), str()]: |
| return random.choice(a.split(b)) | | return random.choice(a.split(b)) |
| case [Iterable() | Sequence(), None]: | | case [Iterable() | Sequence(), None]: |
| return random.choice(list(a)) | | return random.choice(list(a)) |
| case [Iterable() | Sequence(), int()]: | | case [Iterable() | Sequence(), int()]: |
| return random.choices(list(a), k=b) | | return random.choices(list(a), k=b) |