From bae0a6b0380b18a38e80338c404b061617004493 Mon Sep 17 00:00:00 2001 From: qydysky Date: Thu, 8 Feb 2024 00:44:50 +0800 Subject: [PATCH] go 1.22 --- .github/workflows/test.yml | 6 +++--- Random.go | 20 ++++++++++---------- strings/Strings.go | 6 ++---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25ec57b..f040f75 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' - name: Check out code into the Go module directory uses: actions/checkout@v4 @@ -49,7 +49,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' - name: Check out code into the Go module directory uses: actions/checkout@v4 @@ -83,7 +83,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' - name: Check out code into the Go module directory uses: actions/checkout@v4 diff --git a/Random.go b/Random.go index b1402cb..b9c7e43 100644 --- a/Random.go +++ b/Random.go @@ -1,13 +1,12 @@ package part import ( - goRand "math/rand" goCRand "crypto/rand" - "math/big" - "time" + "math/big" + goRand "math/rand/v2" ) -type random struct{ +type random struct { RV []interface{} } @@ -17,7 +16,7 @@ func Rand() *random { func (*random) TrueRandom(max int64) int64 { var e error - if r,e := goCRand.Int(goCRand.Reader, big.NewInt(max)); e == nil { + if r, e := goCRand.Int(goCRand.Reader, big.NewInt(max)); e == nil { return r.Int64() } Logf().E(e.Error()) @@ -25,8 +24,7 @@ func (*random) TrueRandom(max int64) int64 { } func (*random) FakeRandom(max int64) int64 { - r := goRand.New(goRand.NewSource(time.Now().UnixNano())) - return r.Int63n(max) + return goRand.Int64N(max) } func (t *random) MixRandom(min, max int64) int64 { @@ -34,9 +32,11 @@ func (t *random) MixRandom(min, max int64) int64 { if lenght == 0 { return min } else if lenght < 0 { - panic(`max < min`) + panic(`max < min`) } r := t.TrueRandom(lenght) - if r != -1 {return min + r} + if r != -1 { + return min + r + } return min + t.FakeRandom(lenght) -} \ No newline at end of file +} diff --git a/strings/Strings.go b/strings/Strings.go index 285e715..05d3149 100644 --- a/strings/Strings.go +++ b/strings/Strings.go @@ -2,10 +2,9 @@ package part import ( "bytes" - "math/rand" + "math/rand/v2" "strconv" "strings" - "time" ) const ( @@ -27,11 +26,10 @@ func Rand(typel RandType, leng int) string { Letters := []rune(source) LettersL := len(Letters) - r := rand.New(rand.NewSource(time.Now().UnixNano())) var bb bytes.Buffer bb.Grow(leng) for i := 0; i < leng; i++ { - bb.WriteRune(Letters[r.Intn(LettersL)]) + bb.WriteRune(Letters[int(rand.Uint64N(uint64(LettersL)))]) } return bb.String() -- 2.39.2