From 9bb522d7a07499228abc5303153de9fee0055407 Mon Sep 17 00:00:00 2001 From: hoteas Date: Sun, 7 Jan 2018 16:05:32 +0000 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func.go | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/func.go b/func.go index a99f022..c2473bf 100644 --- a/func.go +++ b/func.go @@ -4,10 +4,8 @@ import ( "crypto/md5" "encoding/hex" "math" - "math/rand" "strings" "sync" - "time" ) //安全锁 @@ -111,35 +109,41 @@ func Md5(req string) string { //随机数 func Rand(count int) int { - //随机对象 - var R = rand.New(rand.NewSource(time.Now().UnixNano())) - res := 0 + res := Random() for i := 0; i < count; i++ { res = res * 10 - res = res + R.Intn(10) - if i == 0 && res == 0 { - for { - res = res + R.Intn(10) - if res != 0 { - break - } - } - } } - return res + return ObjToInt(res) +} +func Random() float64 { + v:=float64(0); + m:=float64(0.1); + for i:=0;i<15;i++{ + facter:=map[int]int{0:1,9:1,2:1,7:1,4:1,5:1,6:1,3:1,8:1,1:1} + for k,_:= range facter{ + + v=v+float64(k)*m + break + } + m=m*0.1 + } + + + return v + + } //随机数范围 func RandX(small int, max int) int { res := 0 //随机对象 - var R = rand.New(rand.NewSource(time.Now().UnixNano())) if small == max { return small } for { - res = R.Intn(max) + res = ObjToInt(Random()*float64(max+1)) if res >= small { break }