Skip to content
Permalink
Browse files

Use the current time for initializing RNG.x instead of slow and poten…

…tially blocking crypto/rand
  • Loading branch information...
valyala committed May 31, 2017
1 parent ad48af2 commit 19dd0f0bf014a807b05fd196f4da235af618fc94
Showing with 3 additions and 8 deletions.
  1. +3 −8 fastrand.go
@@ -6,9 +6,8 @@
package fastrand

import (
cryptorand "crypto/rand"
"fmt"
"sync"
"time"
)

// Uint32 returns pseudorandom uint32.
@@ -70,10 +69,6 @@ func (r *RNG) Uint32n(maxN uint32) uint32 {
}

func getRandomUint32() uint32 {
var buf [4]byte
_, err := cryptorand.Read(buf[:])
if err != nil {
panic(fmt.Sprintf("BUG: cannot read random number: %s", err))
}
return uint32(buf[3]) | (uint32(buf[2]) << 8) | (uint32(buf[1]) << 16) | (uint32(buf[0]) << 24)
x := time.Now().UnixNano()
return uint32((x >> 32) ^ x)
}

0 comments on commit 19dd0f0

Please sign in to comment.
You can’t perform that action at this time.