| 1 |
import _random |
| 2 |
import sys |
| 3 |
from _typeshed import SupportsLenAndGetItem |
| 4 |
from collections.abc import Callable, Iterable, MutableSequence, Sequence, Set as AbstractSet |
| 5 |
from fractions import Fraction |
| 6 |
from typing import Any, ClassVar, NoReturn, TypeVar, overload |
| 7 |
from typing_extensions import Self, deprecated |
| 8 |
|
| 9 |
__all__ = [ |
| 10 |
"Random", |
| 11 |
"seed", |
| 12 |
"random", |
| 13 |
"uniform", |
| 14 |
"randint", |
| 15 |
"choice", |
| 16 |
"sample", |
| 17 |
"randrange", |
| 18 |
"shuffle", |
| 19 |
"normalvariate", |
| 20 |
"lognormvariate", |
| 21 |
"expovariate", |
| 22 |
"vonmisesvariate", |
| 23 |
"gammavariate", |
| 24 |
"triangular", |
| 25 |
"gauss", |
| 26 |
"betavariate", |
| 27 |
"paretovariate", |
| 28 |
"weibullvariate", |
| 29 |
"getstate", |
| 30 |
"setstate", |
| 31 |
"getrandbits", |
| 32 |
"choices", |
| 33 |
"SystemRandom", |
| 34 |
"randbytes", |
| 35 |
] |
| 36 |
|
| 37 |
if sys.version_info >= (3, 12): |
| 38 |
__all__ += ["binomialvariate"] |
| 39 |
|
| 40 |
_T = TypeVar("_T") |
| 41 |
|
| 42 |
class Random(_random.Random): |
| 43 |
VERSION: ClassVar[int] |
| 44 |
def __init__(self, x: int | float | str | bytes | bytearray | None = None) -> None: ... |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
if sys.version_info < (3, 10): |
| 49 |
|
| 50 |
def __new__(cls, x: int | float | str | bytes | bytearray | None = None) -> Self: ... |
| 51 |
|
| 52 |
def seed(self, a: int | float | str | bytes | bytearray | None = None, version: int = 2) -> None: ... |
| 53 |
def getstate(self) -> tuple[Any, ...]: ... |
| 54 |
def setstate(self, state: tuple[Any, ...]) -> None: ... |
| 55 |
def randrange(self, start: int, stop: int | None = None, step: int = 1) -> int: ... |
| 56 |
def randint(self, a: int, b: int) -> int: ... |
| 57 |
def randbytes(self, n: int) -> bytes: ... |
| 58 |
def choice(self, seq: SupportsLenAndGetItem[_T]) -> _T: ... |
| 59 |
def choices( |
| 60 |
self, |
| 61 |
population: SupportsLenAndGetItem[_T], |
| 62 |
weights: Sequence[float | Fraction] | None = None, |
| 63 |
*, |
| 64 |
cum_weights: Sequence[float | Fraction] | None = None, |
| 65 |
k: int = 1, |
| 66 |
) -> list[_T]: ... |
| 67 |
if sys.version_info >= (3, 11): |
| 68 |
def shuffle(self, x: MutableSequence[Any]) -> None: ... |
| 69 |
else: |
| 70 |
@overload |
| 71 |
def shuffle(self, x: MutableSequence[Any]) -> None: ... |
| 72 |
@overload |
| 73 |
@deprecated("The `random` parameter is deprecated since Python 3.9; removed in Python 3.11.") |
| 74 |
def shuffle(self, x: MutableSequence[Any], random: Callable[[], float] | None = None) -> None: ... |
| 75 |
if sys.version_info >= (3, 11): |
| 76 |
def sample(self, population: Sequence[_T], k: int, *, counts: Iterable[int] | None = None) -> list[_T]: ... |
| 77 |
else: |
| 78 |
def sample( |
| 79 |
self, population: Sequence[_T] | AbstractSet[_T], k: int, *, counts: Iterable[int] | None = None |
| 80 |
) -> list[_T]: ... |
| 81 |
|
| 82 |
def uniform(self, a: float, b: float) -> float: ... |
| 83 |
def triangular(self, low: float = 0.0, high: float = 1.0, mode: float | None = None) -> float: ... |
| 84 |
if sys.version_info >= (3, 12): |
| 85 |
def binomialvariate(self, n: int = 1, p: float = 0.5) -> int: ... |
| 86 |
|
| 87 |
def betavariate(self, alpha: float, beta: float) -> float: ... |
| 88 |
if sys.version_info >= (3, 12): |
| 89 |
def expovariate(self, lambd: float = 1.0) -> float: ... |
| 90 |
else: |
| 91 |
def expovariate(self, lambd: float) -> float: ... |
| 92 |
|
| 93 |
def gammavariate(self, alpha: float, beta: float) -> float: ... |
| 94 |
if sys.version_info >= (3, 11): |
| 95 |
def gauss(self, mu: float = 0.0, sigma: float = 1.0) -> float: ... |
| 96 |
def normalvariate(self, mu: float = 0.0, sigma: float = 1.0) -> float: ... |
| 97 |
else: |
| 98 |
def gauss(self, mu: float, sigma: float) -> float: ... |
| 99 |
def normalvariate(self, mu: float, sigma: float) -> float: ... |
| 100 |
|
| 101 |
def lognormvariate(self, mu: float, sigma: float) -> float: ... |
| 102 |
def vonmisesvariate(self, mu: float, kappa: float) -> float: ... |
| 103 |
def paretovariate(self, alpha: float) -> float: ... |
| 104 |
def weibullvariate(self, alpha: float, beta: float) -> float: ... |
| 105 |
|
| 106 |
|
| 107 |
class SystemRandom(Random): |
| 108 |
def getrandbits(self, k: int) -> int: ... |
| 109 |
def getstate(self, *args: Any, **kwds: Any) -> NoReturn: ... |
| 110 |
def setstate(self, *args: Any, **kwds: Any) -> NoReturn: ... |
| 111 |
|
| 112 |
_inst: Random |
| 113 |
seed = _inst.seed |
| 114 |
random = _inst.random |
| 115 |
uniform = _inst.uniform |
| 116 |
triangular = _inst.triangular |
| 117 |
randint = _inst.randint |
| 118 |
choice = _inst.choice |
| 119 |
randrange = _inst.randrange |
| 120 |
sample = _inst.sample |
| 121 |
shuffle = _inst.shuffle |
| 122 |
choices = _inst.choices |
| 123 |
normalvariate = _inst.normalvariate |
| 124 |
lognormvariate = _inst.lognormvariate |
| 125 |
expovariate = _inst.expovariate |
| 126 |
vonmisesvariate = _inst.vonmisesvariate |
| 127 |
gammavariate = _inst.gammavariate |
| 128 |
gauss = _inst.gauss |
| 129 |
if sys.version_info >= (3, 12): |
| 130 |
binomialvariate = _inst.binomialvariate |
| 131 |
betavariate = _inst.betavariate |
| 132 |
paretovariate = _inst.paretovariate |
| 133 |
weibullvariate = _inst.weibullvariate |
| 134 |
getstate = _inst.getstate |
| 135 |
setstate = _inst.setstate |
| 136 |
getrandbits = _inst.getrandbits |
| 137 |
randbytes = _inst.randbytes |