Skip to content

Latest commit

 

History

History
107 lines (89 loc) · 3.39 KB

README.md

File metadata and controls

107 lines (89 loc) · 3.39 KB

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

Requirements

  • Golang 1.7 and above

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.