From c7a6a6fff04fed4a5415bf9a36e1413bc2b63ba5 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 10 Apr 2019 23:09:38 +0800 Subject: [PATCH] improve grand.Intn; README updates --- README.MD | 1 + README_ZH.MD | 1 + g/util/grand/grand_intn.go | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.MD b/README.MD index 6059c1ae8..b215dfb70 100644 --- a/README.MD +++ b/README.MD @@ -66,6 +66,7 @@ func main() { # Contributors +- [aloncn](https://github.com/aloncn) - [chenyang351](https://github.com/chenyang351) - [garfieldkwong](https://gitee.com/garfieldkwong) - [hailaz](https://gitee.com/hailaz) diff --git a/README_ZH.MD b/README_ZH.MD index 998f83995..e29248375 100644 --- a/README_ZH.MD +++ b/README_ZH.MD @@ -86,6 +86,7 @@ func main() { # 贡献者 +- [aloncn](https://github.com/aloncn) - [chenyang351](https://github.com/chenyang351) - [garfieldkwong](https://gitee.com/garfieldkwong) - [hailaz](https://gitee.com/hailaz) diff --git a/g/util/grand/grand_intn.go b/g/util/grand/grand_intn.go index 9677a433e..14dcc032e 100644 --- a/g/util/grand/grand_intn.go +++ b/g/util/grand/grand_intn.go @@ -36,10 +36,15 @@ func init() { i ++ } // 充分利用缓冲区数据,随机索引递增 - step = int(buffer[0])%10 - if step == 0 { - step = 2 + for i := 0; i < n; i++ { + step = int(buffer[0])%10 + if step != 0 { + break + } } + if step == 0 { + step = 2 + } for i := 0; i < n - 4; { bufferChan <- binary.BigEndian.Uint32(buffer[i : i + 4]) i += step