Home

Awesome

go_rng

Build Status CircleCI GitHub stars GitHub license GoDoc

A pseudo-random number generator written in Golang v1.3 伪随机数生成器库的Go语言实现

Features

Inspired by:

Supported Distributions and Functionalities:

均匀分布 Uniform Distribution <br /> 伯努利分布 Bernoulli Distribution <br /> 卡方分布 Chi-Squared Distribution <br /> Gamma分布 Gamma Distribution <br /> Beta分布 Beta Distribution <br /> 费舍尔F分布 Fisher's F Distribution <br /> 柯西分布 Cauchy Distribution <br /> 韦伯分布 Weibull Distribution <br /> Pareto分布 Pareto Distribution <br /> 对数高斯分布 Log Normal Distribution <br /> 指数分布 Exponential Distribution <br /> 学生T分布 Student's t-Distribution <br /> 二项分布 Binomial Distribution <br /> 泊松分布 Poisson Distribution <br /> 几何分布 Geometric Distribution <br /> 高斯分布 Gaussian Distribution <br /> 逻辑分布 Logistic Distribution <br /> 狄利克雷分布 Dirichlet Distribution <br />

Requirements

Installation

go get -u -v github.com/leesper/go_rng

Usage

func TestGaussianGenerator(t *testing.T) {
	fmt.Println("=====Testing for GaussianGenerator begin=====")
	grng := NewGaussianGenerator(time.Now().UnixNano())
	fmt.Println("Gaussian(5.0, 2.0): ")
	hist := map[int64]int{}
	for i := 0; i < 10000; i++ {
		hist[int64(grng.Gaussian(5.0, 2.0))]++
	}

	keys := []int64{}
	for k := range hist {
		keys = append(keys, k)
	}
	SortInt64Slice(keys)

	for _, key := range keys {
		fmt.Printf("%d:\t%s\n", key, strings.Repeat("*", hist[key]/200))
	}

	fmt.Println("=====Testing for GaussianGenerator end=====")
	fmt.Println()
}

output:

=====Testing for GaussianGenerator begin=====
Gaussian(5.0, 2.0):
-2:
-1:
0:	*
1:	**
2:	****
3:	*******
4:	*********
5:	*********
6:	*******
7:	****
8:	**
9:
10:
11:
12:
=====Testing for GaussianGenerator end=====

Authors and acknowledgment

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.