Merge pull request #771 from icecrime/uuid_preserve_random_bytes

Reduce consumption of entropy source
This commit is contained in:
Stephen Day 2015-07-28 11:09:50 -07:00
commit a0f7b3ae3c
1 changed files with 3 additions and 1 deletions

View File

@ -49,6 +49,7 @@ func Generate() (u UUID) {
var (
totalBackoff time.Duration
count int
retries int
)
@ -60,9 +61,10 @@ func Generate() (u UUID) {
time.Sleep(b)
totalBackoff += b
_, err := io.ReadFull(rand.Reader, u[:])
n, err := io.ReadFull(rand.Reader, u[count:])
if err != nil {
if retryOnError(err) && retries < maxretries {
count += n
retries++
Loggerf("error generating version 4 uuid, retrying: %v", err)
continue