forked from astaxie/gopkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
186 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
## func Int31n(n int32) int32 | ||
|
||
参数列表 | ||
参数列表: | ||
|
||
- n 期望输出随机值的最大限制值 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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之间的均匀分布的伪随机数的来源. | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## type Zipf struct { | ||
## // contains filtered or unexported fields | ||
## } | ||
|
||
|
||
Zipf 是一个产生Zipf分布变量的结构体. | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|