summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2014-05-24 16:46:59 +0000
committerYawning Angel <yawning@schwanenlied.me>2014-05-24 16:46:59 +0000
commit3e3b07c4e8b619918a6ece624c7072754cab0707 (patch)
treef0bb85d717c5a65e257fa1f2572c0127a30899be
parent8cd2e1f0f9335221fbad892efdbb5e02e787a1e8 (diff)
Don't use math/big when generating random numbers.
-rw-r--r--csrand/csrand.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/csrand/csrand.go b/csrand/csrand.go
index 1700b02..5a86da0 100644
--- a/csrand/csrand.go
+++ b/csrand/csrand.go
@@ -35,8 +35,8 @@ package csrand
import (
cryptRand "crypto/rand"
+ "encoding/binary"
"fmt"
- "math/big"
"math/rand"
)
@@ -52,12 +52,15 @@ type csRandSource struct {
}
func (r csRandSource) Int63() int64 {
- ret, err := cryptRand.Int(cryptRand.Reader, big.NewInt(int64((1<<63)-1)))
+ var src [8]byte
+ err := Bytes(src[:])
if err != nil {
panic(err)
}
+ val := binary.BigEndian.Uint64(src[:])
+ val &= (1<<63 - 1)
- return ret.Int64()
+ return int64(val)
}
func (r csRandSource) Seed(seed int64) {