1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 14:42:27 +08:00

feat:add GetExeDllVersion for fileutil,random,package (#257)

* 增加GetExeDllVersion函数获取exe,dll版本号

* 多打文字

* 定位忘记...

* 单独剥离出来一个为windows的,增加RandNumLen为取指定长度随机数.

* ....

* 增加test测试
This commit is contained in:
今晚打打
2024-10-18 16:17:14 +08:00
committed by GitHub
parent 1671f7856a
commit ed93aae970
9 changed files with 171 additions and 5 deletions

View File

@@ -327,3 +327,12 @@ func UUIdV4() (string, error) {
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
}
// RandNumLen 生成一个长度为len的随机数
// Play: https://go.dev/play/p/jpIalcD5rMo
func RandNumLen(len int) int {
m := int(math.Pow10(len) - 1)
i := int(math.Pow10(len - 1))
ret := rand.Intn(m-i+1) + i
return ret
}

View File

@@ -3,6 +3,7 @@ package random
import (
"reflect"
"regexp"
"strconv"
"testing"
"github.com/duke-git/lancet/v2/internal"
@@ -361,3 +362,9 @@ func TestRandBoolSlice(t *testing.T) {
}
})
}
func TestRandNumLen(t *testing.T) {
t.Parallel()
randi := RandNumLen(6)
assert := internal.NewAssert(t, "TestRandNumLen")
assert.Equal(6, len(strconv.Itoa(randi)))
}