Skip to content

Commit

Permalink
chore: polish random_util (#192)
Browse files Browse the repository at this point in the history
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
  • Loading branch information
hezhangjian authored Oct 27, 2024
1 parent f6ad895 commit a5025a1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/libgox/addr v0.2.0
github.com/libgox/gocollections v0.0.0-20241024144716-59fe0afe6953
github.com/libgox/unicodex v0.0.1
github.com/prometheus/client_golang v1.20.5
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/libgox/addr v0.2.0 h1:he4Vv7lzcGy/1qNpjJufEWRql0S23Ki/j0XpTDMDu3s=
github.com/libgox/addr v0.2.0/go.mod h1:j0hEfpRqTZy4BsstS9Egsn1U0JmNdj/VkbF2VBmJlFw=
github.com/libgox/gocollections v0.0.0-20241024144716-59fe0afe6953 h1:qnlK5i5xCbMjQLqFa6JfNn3r7mtRMwMtuqJjyhgAYK8=
github.com/libgox/gocollections v0.0.0-20241024144716-59fe0afe6953/go.mod h1:Y4udpR8lStv1f67hVWbMCrcTyTvf98bFFsu/ZXvAvZ0=
github.com/libgox/unicodex v0.0.1 h1:yUuZWMVXC5N9dcYgIc3aO7+2M5jN+XVatrU08Y5fC4k=
github.com/libgox/unicodex v0.0.1/go.mod h1:RaB9wNp/oOS0Ew5+Wml7WePjztZ3njXiNid08KOmgjs=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
8 changes: 4 additions & 4 deletions opengemini/random_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ package opengemini
import (
"crypto/rand"
"math/big"
)

const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"github.com/libgox/unicodex/letter"
)

func RandBytes(n int64) []byte {
if n <= 0 {
return []byte{}
}
b := make([]byte, n)
for i := range b {
index, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
index, err := rand.Int(rand.Reader, big.NewInt(int64(letter.EnglishCount)))
if err != nil {
panic(err)
}
b[i] = letters[index.Int64()]
b[i] = letter.EnglishLetters[index.Int64()]
}
return b
}
Expand Down

0 comments on commit a5025a1

Please sign in to comment.