Documentation ¶
Overview ¶
Package rng implements a series of pseudo-random number generator based on a variety of common probability distributions
Index ¶
- type BernoulliGenerator
- type BetaGenerator
- type BinomialGenerator
- type CauchyGenerator
- type ChiSquaredGenerator
- type DirichletGenerator
- type ExpGenerator
- type FisherFGenerator
- type GammaGenerator
- type GaussianGenerator
- type GeometricGenerator
- type LogisticGenerator
- type LognormalGenerator
- type ParetoGenerator
- type PoissonGenerator
- type StudentTGenerator
- type TriangularGenerator
- type UniformGenerator
- func (ung UniformGenerator) Float32() float32
- func (ung UniformGenerator) Float32Range(a, b float32) float32
- func (ung UniformGenerator) Float32n(n float32) float32
- func (ung UniformGenerator) Float64() float64
- func (ung UniformGenerator) Float64Range(a, b float64) float64
- func (ung UniformGenerator) Float64n(n float64) float64
- func (ung UniformGenerator) Int32() int32
- func (ung UniformGenerator) Int32Range(a, b int32) int32
- func (ung UniformGenerator) Int32n(n int32) int32
- func (ung UniformGenerator) Int64() int64
- func (ung UniformGenerator) Int64Range(a, b int64) int64
- func (ung UniformGenerator) Int64n(n int64) int64
- func (ung UniformGenerator) Shuffle(arr []interface{})
- func (ung UniformGenerator) ShuffleRange(arr []interface{}, low, high int)
- type WeibullGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BernoulliGenerator ¶
type BernoulliGenerator struct {
// contains filtered or unexported fields
}
UniformGenerator is a random number generator for uniform distribution. The zero value is invalid, use NewBernoulliGenerator to create a generator
func NewBernoulliGenerator ¶
func NewBernoulliGenerator(seed int64) *BernoulliGenerator
NewBernoulliGenerator returns a bernoulli-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: beng := rng.NewBernoulliGenerator(time.Now().UnixNano())
func (BernoulliGenerator) Bernoulli ¶
func (beng BernoulliGenerator) Bernoulli() bool
Bernoulli returns a bool, which is true with probablity 0.5
func (BernoulliGenerator) Bernoulli_P ¶
func (beng BernoulliGenerator) Bernoulli_P(p float64) bool
Bernoulli_P returns a bool, which is true with probablity p
type BetaGenerator ¶
type BetaGenerator struct {
// contains filtered or unexported fields
}
BetaGenerator is a random number generator for beta distribution. The zero value is invalid, use NewBetaGenerator to create a generator
func NewBetaGenerator ¶
func NewBetaGenerator(seed int64) *BetaGenerator
NewBetaGenerator returns a beta distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: brng := rng.NewBetaGenerator(time.Now().UnixNano())
func (BetaGenerator) Beta ¶
func (brng BetaGenerator) Beta(alpha, beta float64) float64
Beta returns a random number of beta distribution (alpha > 0.0 and beta > 0.0)
type BinomialGenerator ¶
type BinomialGenerator struct {
// contains filtered or unexported fields
}
BinomialGenerator is a random number generator for binomial distribution. The zero value is invalid, use NewBinomialGenerator to create a generator
func NewBinomialGenerator ¶
func NewBinomialGenerator(seed int64) *BinomialGenerator
NewBinomialGenerator returns a binomial-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: bing := rng.NewBinomialGenerator(time.Now().UnixNano())
type CauchyGenerator ¶
type CauchyGenerator struct {
// contains filtered or unexported fields
}
CauchyGenerator is a random number generator for cauchy distribution. The zero value is invalid, use NewCauchyGenerator to create a generator
func NewCauchyGenerator ¶
func NewCauchyGenerator(seed int64) *CauchyGenerator
NewCauchyGenerator returns a cauchy-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: crng := rng.NewCauchyGenerator(time.Now().UnixNano())
func (CauchyGenerator) Cauchy ¶
func (crng CauchyGenerator) Cauchy(x0, gamma float64) float64
Cauchy returns a random number of cauchy distribution
func (CauchyGenerator) StandardCauchy ¶
func (crng CauchyGenerator) StandardCauchy() float64
StandardCauchy() returns a random number of standard cauchy distribution (x0 = 0.0, gamma = 1.0)
type ChiSquaredGenerator ¶
type ChiSquaredGenerator struct {
// contains filtered or unexported fields
}
ChiSquaredGenerator is a random number generator for chi-squared distribution. The zero value is invalid, use NewChiSquaredGenerator to create a generator
func NewChiSquaredGenerator ¶
func NewChiSquaredGenerator(seed int64) *ChiSquaredGenerator
NewChiSquaredGenerator returns a chi-squared distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: crng := rng.NewChiSquaredGenerator(time.Now().UnixNano())
func (ChiSquaredGenerator) ChiSquared ¶
func (crng ChiSquaredGenerator) ChiSquared(freedom int64) float64
ChiSquared returns a random number of chi-squared distribution (freedom > 0)
type DirichletGenerator ¶
type DirichletGenerator struct {
// contains filtered or unexported fields
}
DirichletGenerator is a random number generator for dirichlet distribution. The zero value is invalid, use NewDirichletGenerator to create a generator
func NewDirichletGenerator ¶
func NewDirichletGenerator(seed int64) *DirichletGenerator
NewDirichletGenerator returns a dirichlet-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: drng := rng.NewDirichletGenerator(time.Now().UnixNano())
func (DirichletGenerator) Dirichlet ¶
func (drng DirichletGenerator) Dirichlet(alphas []float64) []float64
Dirichlet returns random numbers of dirichlet distribution (alpha > 0.0, for alpha in alphas)
func (DirichletGenerator) FlatDirichlet ¶
func (drng DirichletGenerator) FlatDirichlet(n int) []float64
FlatDirichlet returns random numbers of flat-dirichlet distribution (n > 0)
func (DirichletGenerator) SymmetricDirichlet ¶
func (drng DirichletGenerator) SymmetricDirichlet(alpha float64, n int) []float64
SymmetricDirichlet returns random numbers of symmetric-dirichlet distribution (alpha > 0.0 and n > 0)
type ExpGenerator ¶
type ExpGenerator struct {
// contains filtered or unexported fields
}
ExpGenerator is a random number generator for exponential distribution. The zero value is invalid, use NewExpGenerator to create a generator
func NewExpGenerator ¶
func NewExpGenerator(seed int64) *ExpGenerator
NewExpGenerator returns a exponential-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: erng := rng.NewExpGenerator(time.Now().UnixNano())
func (ExpGenerator) Exp ¶
func (erng ExpGenerator) Exp(lambda float64) float64
Exp returns a random number of exponential distribution
type FisherFGenerator ¶
type FisherFGenerator struct {
// contains filtered or unexported fields
}
FisherFGenerator is a random number generator for Fisher's F distribution. The zero value is invalid, use NewFisherFGenerator to create a generator
func NewFisherFGenerator ¶
func NewFisherFGenerator(seed int64) *FisherFGenerator
NewFisherFGenerator returns a Fisher's F distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: frng := rng.NewFisherFGenerator(time.Now().UnixNano())
func (FisherFGenerator) Fisher ¶
func (frng FisherFGenerator) Fisher(d1, d2 int64) float64
Fisher returns a random number of Fisher's F distribution (d1 > 0 and d2 > 0)
type GammaGenerator ¶
type GammaGenerator struct {
// contains filtered or unexported fields
}
GammaGenerator is a random number generator for gamma distribution. The zero value is invalid, use NewGammaGenerator to create a generator
func NewGammaGenerator ¶
func NewGammaGenerator(seed int64) *GammaGenerator
NewGammaGenerator returns a gamma distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: grng := rng.NewGammaGenerator(time.Now().UnixNano())
func (GammaGenerator) Gamma ¶
func (grng GammaGenerator) Gamma(alpha, beta float64) float64
Gamma returns a random number of gamma distribution (alpha > 0.0 and beta > 0.0)
type GaussianGenerator ¶
type GaussianGenerator struct {
// contains filtered or unexported fields
}
GaussianGenerator is a random number generator for gaussian distribution. The zero value is invalid, use NewGaussianGenerator to create a generator
func NewGaussianGenerator ¶
func NewGaussianGenerator(seed int64) *GaussianGenerator
NewGaussianGenerator returns a gaussian-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: crng := rng.NewGaussianGenerator(time.Now().UnixNano())
func (GaussianGenerator) Gaussian ¶
func (grng GaussianGenerator) Gaussian(mean, stddev float64) float64
Gaussian returns a random number of gaussian distribution Gauss(mean, stddev^2)
func (GaussianGenerator) StdGaussian ¶
func (grng GaussianGenerator) StdGaussian() float64
StdGaussian returns a random number of standard gaussian distribution
type GeometricGenerator ¶
type GeometricGenerator struct {
// contains filtered or unexported fields
}
GeometricGenerator is a random number generator for geometric distribution. The zero value is invalid, use NewGeometryGenerator to create a generator
func NewGeometricGenerator ¶
func NewGeometricGenerator(seed int64) *GeometricGenerator
NewGeometricGenerator returns a geometric-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: grng := rng.NewGeometricGenerator(time.Now().UnixNano())
func (GeometricGenerator) Geometric ¶
func (grng GeometricGenerator) Geometric(p float64) int64
Geometric returns a random number X ~ binomial(n, p)
type LogisticGenerator ¶
type LogisticGenerator struct {
// contains filtered or unexported fields
}
LogisticGenerator is a random number generator for logistic distribution. The zero value is invalid, use NewLogisticGenerator to create a generator
func NewLogisticGenerator ¶
func NewLogisticGenerator(seed int64) *LogisticGenerator
NewLogisticGenerator returns a logistic-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: lrng := rng.NewLogisticGenerator(time.Now().UnixNano())
func (LogisticGenerator) Logistic ¶
func (lrng LogisticGenerator) Logistic(mu, s float64) float64
Logistic returns a random number of logistic distribution
type LognormalGenerator ¶
type LognormalGenerator struct {
// contains filtered or unexported fields
}
LognormalGenerator is a random number generator for lognormal distribution. The zero value is invalid, use NewLognormalGenerator to create a generator
func NewLognormalGenerator ¶
func NewLognormalGenerator(seed int64) *LognormalGenerator
NewLognormalGenerator returns a lognormal-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: crng := rng.NewLognormalGenerator(time.Now().UnixNano())
func (LognormalGenerator) Lognormal ¶
func (lnng LognormalGenerator) Lognormal(mean, stddev float64) float64
Lognormal return a random number of lognormal distribution
type ParetoGenerator ¶
type ParetoGenerator struct {
// contains filtered or unexported fields
}
ParetoGenerator is a random number generator for type I pareto distribution. The zero value is invalid, use NewParetoGenerator to create a generator
func NewParetoGenerator ¶
func NewParetoGenerator(seed int64) *ParetoGenerator
NewParetoGenerator returns a type I pareto-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: crng := rng.NewParetoGenerator(time.Now().UnixNano())
func (ParetoGenerator) Pareto ¶
func (prng ParetoGenerator) Pareto(alpha float64) float64
Pareto returns a random number of type I pareto distribution (alpha > 0,0)
type PoissonGenerator ¶
type PoissonGenerator struct {
// contains filtered or unexported fields
}
PoissonGenerator is a random number generator for possion distribution. The zero value is invalid, use NewPoissonGenerator to create a generator
func NewPoissonGenerator ¶
func NewPoissonGenerator(seed int64) *PoissonGenerator
NewPoissonGenerator returns a possion-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: prng := rng.NewPoissonGenerator(time.Now().UnixNano())
func (PoissonGenerator) Poisson ¶
func (prng PoissonGenerator) Poisson(lambda float64) int64
Poisson returns a random number of possion distribution
type StudentTGenerator ¶
type StudentTGenerator struct {
// contains filtered or unexported fields
}
StudentTGenerator is a random number generator for student-t distribution. The zero value is invalid, use NewStudentTGenerator to create a generator
func NewStudentTGenerator ¶
func NewStudentTGenerator(seed int64) *StudentTGenerator
NewStudentTGenerator returns a student-t distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: stng := rng.NewStudentTGenerator(time.Now().UnixNano())
func (StudentTGenerator) Student ¶
func (stng StudentTGenerator) Student(freedom int64) float64
Student returns a random number of student-t distribution (freedom > 0.0)
type TriangularGenerator ¶
type TriangularGenerator struct {
// contains filtered or unexported fields
}
TriangularGenerator is a random number generator for Triangular distribution.
func NewTriangularGenerator ¶
func NewTriangularGenerator(seed int64) *TriangularGenerator
NewTriangularGenerator returns a Triangular-distribution generator
func (TriangularGenerator) TriangularObj ¶
func (Trng TriangularGenerator) TriangularObj(a, b, c float64) float64
TriangularObj returns value when x in[a,c] then cdf = (x-a)^2/((b-a)(c-a)) ,when x in(c,b] then 1 - (b-x)^2/((b-a)(b-c)) when x in[0,(c-a)/(b-a)] then invcdf = a+ sqrt(x*(b-1)(c-a)) ,when x in((c-a)/(b-a),1] then invcdf = b - sqrt((1-x)*(b-a)*(b-c))
type UniformGenerator ¶
type UniformGenerator struct {
// contains filtered or unexported fields
}
UniformGenerator is a random number generator for uniform distribution. The zero value is invalid, use NewUniformGenerator to create a generator
func NewUniformGenerator ¶
func NewUniformGenerator(seed int64) *UniformGenerator
NewUniformGenerator returns a uniform-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: urng := rng.NewUniformGenerator(time.Now().UnixNano())
func (UniformGenerator) Float32 ¶
func (ung UniformGenerator) Float32() float32
Float32 returns a random float32 in [0.0, 1.0)
func (UniformGenerator) Float32Range ¶
func (ung UniformGenerator) Float32Range(a, b float32) float32
Float32Range returns a random float32 in [a, b)
func (UniformGenerator) Float32n ¶
func (ung UniformGenerator) Float32n(n float32) float32
Float32n returns a random float32 in [0.0, n)
func (UniformGenerator) Float64 ¶
func (ung UniformGenerator) Float64() float64
Float64 returns a random float64 in [0.0, 1.0)
func (UniformGenerator) Float64Range ¶
func (ung UniformGenerator) Float64Range(a, b float64) float64
Float32Range returns a random float32 in [a, b)
func (UniformGenerator) Float64n ¶
func (ung UniformGenerator) Float64n(n float64) float64
Float64n returns a random float64 in [0.0, n)
func (UniformGenerator) Int32 ¶
func (ung UniformGenerator) Int32() int32
Int32 returns a random uint32
func (UniformGenerator) Int32Range ¶
func (ung UniformGenerator) Int32Range(a, b int32) int32
Int32Range returns a random uint32 in [a, b)
func (UniformGenerator) Int32n ¶
func (ung UniformGenerator) Int32n(n int32) int32
Int32n returns a random uint32 in [0, n)
func (UniformGenerator) Int64 ¶
func (ung UniformGenerator) Int64() int64
Int64 returns a random uint64
func (UniformGenerator) Int64Range ¶
func (ung UniformGenerator) Int64Range(a, b int64) int64
Int64Range returns a random uint64 in [a, b)
func (UniformGenerator) Int64n ¶
func (ung UniformGenerator) Int64n(n int64) int64
Int64n returns a random uint64 in [0, n)
func (UniformGenerator) Shuffle ¶
func (ung UniformGenerator) Shuffle(arr []interface{})
Shuffle rearrange the elements of an array in random order
func (UniformGenerator) ShuffleRange ¶
func (ung UniformGenerator) ShuffleRange(arr []interface{}, low, high int)
Shuffle rearrange the elements of the subarray[low..high] in random order
type WeibullGenerator ¶
type WeibullGenerator struct {
// contains filtered or unexported fields
}
WeibullGenerator is a random number generator for weibull distribution. The zero value is invalid, use NewWeibullGenerator to create a generator
func NewWeibullGenerator ¶
func NewWeibullGenerator(seed int64) *WeibullGenerator
NewWeibullGenerator returns a weibull-distribution generator it is recommended using time.Now().UnixNano() as the seed, for example: wrng := rng.NewWeibullGenerator(time.Now().UnixNano())
func (WeibullGenerator) Weibull ¶
func (wrng WeibullGenerator) Weibull(lambda, k float64) float64
Weibull returns a random number of weibull distribution (lambda > 0.0 and k > 0.0)