src/pylib/Lib/random_impl/proc_others

Search:
Group by:
Source   Edit  

Procs

func betavariate(self: PyRandom; alpha, beta: float): float {.
    ...raises: [ValueError], tags: [], forbids: [].}

Beta distribution.

Conditions on the parameters are alpha > 0 and beta > 0. Returned values range between 0 and 1.

The mean (expected value) and variance of the random variable are:

 E[X] = alpha / (alpha + beta)
 Var[X] = alpha * beta / ((alpha + beta)**2 * (alpha + beta + 1))

Source   Edit  
func binomialvariate(self: PyRandom; n = 1.0; p = 0.5): float {.
    ...raises: [ValueError], tags: [], forbids: [].}

Binomial random variable.

Gives the number of successes for n independent trials with the probability of success in each trial being p:

sum(random() < p for i in range(n))

Returns an integer in the range: 0 <= X <= n

The mean (expected value) and variance of the random variable are:

E[X] = n * p
Var[x] = n * p * (1 - p)

Source   Edit  
func choices[T](self: PyRandom; population: openArray[T];
                weights = none(openArray[T]);
                cum_weights = none(openArray[T]); k = 1): seq[T]
Source   Edit  
func expovariate(self: PyRandom; lambd = 1.0): float {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func gammavariate(self: PyRandom; alpha, beta: float): float {.
    ...raises: [ValueError], tags: [], forbids: [].}
Source   Edit  
func index[I: Ordinal](x: I): int
Source   Edit  
func lognormalvariate(self: PyRandom; mu, sigma: float): float {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func normalvariate(self: PyRandom; mu = 0.0; sigma = 1.0): float {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func paretovariate(self: PyRandom; alpha: float): float {....raises: [], tags: [],
    forbids: [].}
Pareto distribution. alpha is the shape parameter. Source   Edit  
func randrange[I: SomeInteger](self: PyRandom; istart, istop: I; istep: I): I
Source   Edit  
func randrange[T; I: Indexable[T]](self: PyRandom; start, stop, step: I): T
Source   Edit  
func sample[T](self: PyRandom; population: openArray[T]; k: int): seq[T]
Source   Edit  
func sample[T](self: PyRandom; population: openArray[T]; k: int;
               counts: openArray[T]): seq[T]
Source   Edit  
func shuffle[T](self: PyRandom; x: var seq[T])
Source   Edit  
func triangular[F: SomeFloat](self: PyRandom; low: F = 0.0; high: F = 1.0): F
Source   Edit  
func triangular[F: SomeFloat](self: PyRandom; low: F = 0.0; high: F = 1.0;
                              mode: F): F
Source   Edit  
func vonmisesvariate(self: PyRandom; mu, kappa: float): float {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func weibullvariate(self: PyRandom; alpha, beta: float): float {....raises: [],
    tags: [], forbids: [].}

Weibull distribution.

alpha is the scale parameter and beta is the shape parameter.

Source   Edit  

Methods

method getrandbits(self: PyRandom; k: int): int {.base, ...raises: [], tags: [],
    forbids: [].}
_random_Random_getrandbits_impl
Hint: raises ValueError if k >= 8*sizeof(int)
Source   Edit  
method randbytes(self: PyRandom; n: int): string {.base, ...raises: [], tags: [],
    forbids: [].}
return self.getrandbits(n * 8).to_bytes(n, 'little') here we use _random_Random_getrandbits_impl Source   Edit  

Templates

template betavariate(alpha, beta: float): float
Source   Edit  
template binomialvariate(n = 1.0; p = 0.5): float
Source   Edit  
template choices[T](population: openArray[T]; weights = none(openArray[T]);
                    cum_weights = none(openArray[T]); k = 1): seq[T]
Source   Edit  
template expovariate(lambd = 1.0): float
Source   Edit  
template gammavariate(alpha, beta: float): float
Source   Edit  
template getrandbits(k: int): int
Source   Edit  
template lognormalvariate(mu, sigma: float): float
Source   Edit  
template normalvariate(mu = 0.0; sigma = 1.0): float
Source   Edit  
template paretovariate(alpha: float): float
Source   Edit  
template randbytes(n: int): string
Source   Edit  
template randrange[I: SomeInteger](istart, istop: I; istep: I): I
Source   Edit  
template randrange[T; I: Indexable[T]](start, stop, step: I): T
Source   Edit  
template sample[T](population: openArray[T]; k: int): seq[T]
Source   Edit  
template sample[T](population: openArray[T]; k: int; counts: openArray[T]): seq[
    T]
Source   Edit  
template shuffle[T](x: var seq[T])
Source   Edit  
template shuffleImpl(self: PyRandom; x)
inner. unstable. Source   Edit  
template triangular[F: SomeFloat](low: F = 0.0; high: F = 1.0): F
Source   Edit  
template triangular[F: SomeFloat](low: F = 0.0; high: F = 1.0; mode: F): F
Source   Edit  
template vonmisesvariate(mu, kappa: float): float
Source   Edit  
template weibullvariate(alpha, beta: float): float
Source   Edit