Skip to content

Commit

Permalink
初步弄完math/rand
Browse files Browse the repository at this point in the history
  • Loading branch information
ififi committed Mar 17, 2013
1 parent 66c8205 commit 8b07908
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 21 deletions.
2 changes: 1 addition & 1 deletion math/rand/Int31n.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## func Int31n(n int32) int32

参数列表
参数列表:

- n 期望输出随机值的最大限制值

Expand Down
43 changes: 43 additions & 0 deletions math/rand/NewSource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## func NewSource(seed int64) Source

参数列表:

- int64类型的值作为种子值


返回值:

- Source结构体

功能说明:

该函数主要返回一个指定种子的随机数产生器.


代码实例:

package main

import (
"fmt"
"math/rand"
"time"
)

func main() {
n := 10
i := 0

r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i < n {
fmt.Println(r.Int())
i += 1
}
}







47 changes: 47 additions & 0 deletions math/rand/NewZipf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf

参数列表:

- r *Rand 随机值产生器结构体指针
- s float64 Zipf公式的s参数
- v float64 Zipf公司的v参数
- imax uint64 分布区间的最大值


返回值:

- Zipf 指针

功能说明:

该函数实现取值是0到imax之间与(v+k)**(-s)成比例的Zipf分布.


代码实例:

package main

import (
"fmt"
"math/rand"
"time"
)

func main() {
n := 10
i := 0

r := rand.New(rand.NewSource(time.Now().UnixNano()))
zipf := rand.NewZipf(r, 3.14, 2.72, 5000)
for i < n {
fmt.Println(zipf.Uint64())
i += 1
}
}







40 changes: 20 additions & 20 deletions math/rand/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
- [func Perm(n int) []int](Perm.md)
- [func Seed(seed int64)](Seed.md)
- [func Uint32() uint32](Uint32.md)
- type Rand
- [func New(src Source) *Rand](New.md)
- [func (r *Rand) ExpFloat64() float64](Rand-ExpFloat64.md)
- [func (r *Rand) Float32() float32](Rand-Float32.md)
- [func (r *Rand) Float64() float64](Rand-Float64.md)
- [func (r *Rand) Int() int](Rand-Int.md)
- [func (r *Rand) Int31() int32](Rand-Int31.md)
- [func (r *Rand) Int31n(n int32) int32](Rand-Int31n.md)
- [func (r *Rand) Int63() int64](Rand-Int63.md)
- [func (r *Rand) Int63n(n int64) int64](Rand-Int63n.md)
- [func (r *Rand) Intn(n int) int](Rand-Intn.md)
- [func (r *Rand) NormFloat64() float64](Rand-NormFloat64.md)
- [func (r *Rand) Perm(n int) []int](Rand-Perm.md)
- [func (r *Rand) Seed(seed int64)](Rand-Seed.md)
- [func (r *Rand) Uint32() uint32](Rand-Uint32.md)
- type Source
- func NewSource(seed int64) Source
- type Zipf
- func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf
- func (z *Zipf) Uint64() uint64
- [type Rand](Rand.md)
- [func New(src Source) *Rand](New.md)
- [func (r *Rand) ExpFloat64() float64](Rand-ExpFloat64.md)
- [func (r *Rand) Float32() float32](Rand-Float32.md)
- [func (r *Rand) Float64() float64](Rand-Float64.md)
- [func (r *Rand) Int() int](Rand-Int.md)
- [func (r *Rand) Int31() int32](Rand-Int31.md)
- [func (r *Rand) Int31n(n int32) int32](Rand-Int31n.md)
- [func (r *Rand) Int63() int64](Rand-Int63.md)
- [func (r *Rand) Int63n(n int64) int64](Rand-Int63n.md)
- [func (r *Rand) Intn(n int) int](Rand-Intn.md)
- [func (r *Rand) NormFloat64() float64](Rand-NormFloat64.md)
- [func (r *Rand) Perm(n int) []int](Rand-Perm.md)
- [func (r *Rand) Seed(seed int64)](Rand-Seed.md)
- [func (r *Rand) Uint32() uint32](Rand-Uint32.md)
- [type Source](Source.md)
- [func NewSource(seed int64) Source](NewSource.md)
- [type Zipf](Zipf.md)
- [func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf](NewZipf.md)
- [func (z *Zipf) Uint64() uint64](Zipf-Uint64.md)
18 changes: 18 additions & 0 deletions math/rand/Source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## type Source interface {
## Int63() int64
## Seed(seed int64)
## }


Source 结构体是0到2^63-1之间的均匀分布的伪随机数的来源.











40 changes: 40 additions & 0 deletions math/rand/Zipf-Uint64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## func (*Zipf) Uint64 uint64


返回值:

- unit64

功能说明:

该函数返回一个按照Zipf对象表述的Zipf分布的值.


代码实例:

package main

import (
"fmt"
"math/rand"
"time"
)

func main() {
n := 10
i := 0

r := rand.New(rand.NewSource(time.Now().UnixNano()))
zipf := rand.NewZipf(r, 3.14, 2.72, 5000)
for i < n {
fmt.Println(zipf.Uint64())
i += 1
}
}







17 changes: 17 additions & 0 deletions math/rand/Zipf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## type Zipf struct {
## // contains filtered or unexported fields
## }


Zipf 是一个产生Zipf分布变量的结构体.











0 comments on commit 8b07908

Please sign in to comment.