1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
dudaodong f7aaa1ed2a fix: fix issue #75 2023-02-23 11:43:41 +08:00
dudaodong ef19a414bc doc: fix doc error 2023-02-23 10:58:43 +08:00
dudaodong 65704dea06 doc: fix doc error 2023-02-23 10:57:48 +08:00
4 changed files with 17 additions and 5 deletions
+1
View File
@@ -29,6 +29,7 @@ import (
- [Compose](#Compose) - [Compose](#Compose)
- [Debounced](#Debounced) - [Debounced](#Debounced)
- [Delay](#Delay) - [Delay](#Delay)
- [Schedule](#Schedule)
- [Pipeline](#Pipeline) - [Pipeline](#Pipeline)
- [Watcher](#Watcher) - [Watcher](#Watcher)
+1
View File
@@ -29,6 +29,7 @@ import (
- [Compose](#Compose) - [Compose](#Compose)
- [Debounced](#Debounced) - [Debounced](#Debounced)
- [Delay](#Delay) - [Delay](#Delay)
- [Schedule](#Schedule)
- [Pipeline](#Pipeline) - [Pipeline](#Pipeline)
- [Watcher](#Watcher) - [Watcher](#Watcher)
+1
View File
@@ -33,6 +33,7 @@ import (
- [UpperKebabCase](#UpperKebabCase) - [UpperKebabCase](#UpperKebabCase)
- [LowerFirst](#LowerFirst) - [LowerFirst](#LowerFirst)
- [UpperFirst](#UpperFirst) - [UpperFirst](#UpperFirst)
- [Pad](#Pad)
- [PadEnd](#PadEnd) - [PadEnd](#PadEnd)
- [PadStart](#PadStart) - [PadStart](#PadStart)
- [Reverse](#Reverse) - [Reverse](#Reverse)
+13 -4
View File
@@ -19,6 +19,10 @@ const (
Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
) )
func init() {
rand.Seed(time.Now().UnixNano())
}
// RandInt generate random int between min and max, maybe min, not be max. // RandInt generate random int between min and max, maybe min, not be max.
// Play: https://go.dev/play/p/pXyyAAI5YxD // Play: https://go.dev/play/p/pXyyAAI5YxD
func RandInt(min, max int) int { func RandInt(min, max int) int {
@@ -28,9 +32,12 @@ func RandInt(min, max int) int {
if max < min { if max < min {
min, max = max, min min, max = max, min
} }
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return r.Intn(max-min) + min // fix: https://github.com/duke-git/lancet/issues/75
// r := rand.New(rand.NewSource(time.Now().UnixNano()))
// return r.Intn(max-min) + min
return rand.Intn(max-min) + min
} }
// RandBytes generate random byte slice. // RandBytes generate random byte slice.
@@ -81,10 +88,12 @@ func RandNumeralOrLetter(length int) string {
// random generate a random string based on given string range. // random generate a random string based on given string range.
func random(s string, length int) string { func random(s string, length int) string {
b := make([]byte, length) b := make([]byte, length)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
// fix: https://github.com/duke-git/lancet/issues/75
// r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := range b { for i := range b {
b[i] = s[r.Int63()%int64(len(s))] b[i] = s[rand.Int63()%int64(len(s))]
} }
return string(b) return string(b)