Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
//生成随机字符串
|
||||
func RandStr(strLen int) string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
data := make([]byte, strLen)
|
||||
var num int
|
||||
for i := 0; i < strLen; i++ {
|
||||
num = rand.Intn(57) + 65
|
||||
for {
|
||||
if num > 90 && num < 97 {
|
||||
num = rand.Intn(57) + 65
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
data[i] = byte(num)
|
||||
}
|
||||
return string(data)
|
||||
}
|
||||
func ArrayReverseInt(s []int) []int {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
return s
|
||||
}
|
||||
func ArrayReverseByte(s []byte) []byte {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user