A pseudo-random number generator wriiten in Golang
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.yml
LICENSE
README.md
bernoulli.go
beta.go
binomial.go
cauchy.go
chi_square.go
dirichlet.go
exponential.go
fisher_f.go
gamma.go
gauss.go
geometry.go
logistic.go
lognormal.go
pareto.go
poisson.go
rng_test.go
student_t.go
uniform.go
weibull.go

README.md

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.