diff --git a/random/random.go b/random/random.go index bceca50..9d7dc5f 100644 --- a/random/random.go +++ b/random/random.go @@ -329,6 +329,7 @@ func UUIdV4() (string, error) { } // 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)) diff --git a/random/random_test.go b/random/random_test.go index f7df09d..9f0f5e0 100644 --- a/random/random_test.go +++ b/random/random_test.go @@ -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))) +}