src/pylib/Lib/random

Source   Edit  

Note: global random state is indenpendent from Nim's std/random's
Note: random() algorithm differs Python's, meaning the same seed produces different result

TODO: PyRandom uses method; impl SysRandom TODO: commandLine pysince(3,13)

Procs

func choice[T](self: PyRandom; ls: Sequence[T]): T
Source   Edit  
func choices[T](self: PyRandom; population: Sequence[T];
                weights: NoneType | Sequence[T] = None;
                cum_weights: NoneType | Sequence[T] = None; k = 1): PyList[T]
Source   Edit  
func randbytes(self: PyRandom; n: int): PyBytes {....raises: [], tags: [],
    forbids: [].}
Admonition: since Python 3.9
Source   Edit  
func sample[T](self: PyRandom; population: Sequence[T]; k: int): PyList[T]
Source   Edit  
func sample[T](self: PyRandom; population: Sequence[T]; k: int;
               counts: Sequence[T]): PyList[T]
Admonition: since Python 3.9
Source   Edit  
proc seed(self: PyRandom; _: NoneType) {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc seed(self: PyRandom; val: int64) {....raises: [], tags: [], forbids: [].}
Source   Edit  
func shuffle[T](self: PyRandom; x: var PyList[T])
Source   Edit  
func triangular[F: SomeFloat](self: PyRandom; low: F = 0.0; high: F = 1.0;
                              mode: F | NoneType = None): F
Source   Edit  

Templates

template choice[T](ls: Sequence[T]): T
Source   Edit  
template choices[T](population: Sequence[T];
                    weights: NoneType | Sequence[T] = None;
                    cum_weights: NoneType | Sequence[T] = None; k = 1): PyList[T]
Source   Edit  
template randbytes(n: int): PyBytes
Source   Edit  
template sample[T](population: Sequence[T]; k: int): PyList[T]
Source   Edit  
template sample[T](population: Sequence[T]; k: int; counts: Sequence[T]): PyList[
    T]
Source   Edit  
template seed(_: NoneType)
Source   Edit  
template seed(val: int64)
Source   Edit  
template shuffle[T](x: var PyList[T])
Source   Edit  
template triangular[F: SomeFloat](low: F = 0.0; high: F = 1.0;
                                  mode: F | NoneType = None): F
Source   Edit