]> 127.0.0.1 Git - part/.git/commitdiff
53
authorqydysky <qydysky@foxmail.com>
Sun, 30 Aug 2020 23:09:20 +0000 (07:09 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 30 Aug 2020 23:09:20 +0000 (07:09 +0800)
Random.go [new file with mode: 0644]
Sys.go

diff --git a/Random.go b/Random.go
new file mode 100644 (file)
index 0000000..07d1124
--- /dev/null
+++ b/Random.go
@@ -0,0 +1,36 @@
+package part
+
+import (
+       goRand "math/rand"
+       goCRand "crypto/rand"
+       "math/big"
+       "time"
+)
+
+type random struct{
+       RV []interface{}
+}
+
+func Rand() *random {
+       return &random{}
+}
+
+func (*random) TrueRandom(max int64) int64 {
+       var e error
+       if r,e := goCRand.Int(goCRand.Reader, big.NewInt(max)); e == nil {
+               return r.Int64()
+       }
+       Logf().E(e.Error())
+       return -1
+}
+
+func (*random) FakeRandom(max int64) int64 {
+       r := goRand.New(goRand.NewSource(time.Now().UnixNano()))
+       return r.Int63n(max)
+}
+
+func (t *random) MixRandom(max int64) int64 {
+       r := t.TrueRandom(max)
+       if r != -1 {return r}
+       return t.FakeRandom(max)
+}
\ No newline at end of file
diff --git a/Sys.go b/Sys.go
index 13388e0f57a95ce8450efc12a171a07eff09de3a..1266125bb6e9e9b1c6fd88dec45c4202d1bc7284 100644 (file)
--- a/Sys.go
+++ b/Sys.go
@@ -61,6 +61,13 @@ func (this *sys) Timeoutf(Timeout int) {
     time.Sleep(time.Duration(Timeout)*time.Second)
 }
 
+func (this *sys) MTimeoutf(Millisecond int) {
+       this.Lock()
+       defer this.Unlock()
+       
+    time.Sleep(time.Duration(Millisecond)*time.Millisecond)
+}
+
 func (this *sys) GetSys(sys string)bool{
        this.RV = append(this.RV, runtime.GOOS)
     return runtime.GOOS==sys