Skip to content

Commit

Permalink
调整:随机数
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 16, 2024
1 parent e908a58 commit 79c91b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import (
"github.com/farseer-go/fs/net"
"github.com/farseer-go/fs/sonyflake"
"github.com/farseer-go/fs/stopwatch"
"math/rand"
"os"
"strconv"
"strings"
"sync"
"time"
)

var (
Expand All @@ -39,7 +37,8 @@ func Initialize[TModule modules.FarseerModule](appName string) {
sw := stopwatch.StartNew()
Context = context.Background()
onceInit.Do(func() {
rand.Seed(time.Now().UnixNano())
//rand.New(rand.NewSource(time.Now().UnixNano()))
//rand.Seed(time.Now().UnixNano())
core.AppName = appName
core.ProcessId = os.Getppid()
core.HostName, _ = os.Hostname()
Expand Down
3 changes: 2 additions & 1 deletion parse/randString.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package parse
import (
"encoding/hex"
"math/rand"
"time"
)

// RandString 随机字符串
func RandString(length int) string {
b := make([]byte, length)
rand.Read(b)
rand.New(rand.NewSource(time.Now().UnixNano())).Read(b)
return hex.EncodeToString(b)[0:length]
}

0 comments on commit 79c91b9

Please sign in to comment.