mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-28 22:33:59 -06:00
random: extract to a separate module
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import random
|
||||
import typing as T
|
||||
|
||||
|
||||
def seed(seed: T.Any) -> None:
|
||||
random.seed(seed)
|
||||
|
||||
|
||||
def choice(source: T.Iterable[T.Any]) -> T.Any:
|
||||
return random.choice(source)
|
||||
|
||||
|
||||
def below(num: int) -> int:
|
||||
return random.randint(0, num - 1)
|
||||
|
||||
|
||||
def below_low(num: int) -> int:
|
||||
return min(below(num), below(num))
|
||||
|
||||
|
||||
def odds(chance: int, out_of: int) -> bool:
|
||||
return below(out_of) < chance
|
||||
Reference in New Issue
Block a user