Skip to content

Commit d770e29

Browse files
author
Roberto Santalla
authored
Use crypto/rand entropy source for ulid.New (#271)
Use crypto/rand.Reader as an entropy source for uuid Signed-off-by: Roberto Santalla <[email protected]>
1 parent 54324d6 commit d770e29

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

model.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package kallax
22

33
import (
44
"bytes"
5+
"crypto/rand"
56
"database/sql"
67
"database/sql/driver"
78
"encoding/hex"
89
"fmt"
9-
"math/rand"
10-
"sync"
1110
"time"
1211

1312
"github.com/oklog/ulid"
@@ -227,13 +226,6 @@ type Record interface {
227226
Saveable
228227
}
229228

230-
var randPool = &sync.Pool{
231-
New: func() interface{} {
232-
seed := time.Now().UnixNano() + rand.Int63()
233-
return rand.NewSource(seed)
234-
},
235-
}
236-
237229
// ULID is an ID type provided by kallax that is a lexically sortable UUID.
238230
// The internal representation is an ULID (https://github.com/oklog/ulid).
239231
// It already implements sql.Scanner and driver.Valuer, so it's perfectly
@@ -242,11 +234,7 @@ type ULID uuid.UUID
242234

243235
// NewULID returns a new ULID, which is a lexically sortable UUID.
244236
func NewULID() ULID {
245-
entropy := randPool.Get().(rand.Source)
246-
id := ULID(ulid.MustNew(ulid.Timestamp(time.Now()), rand.New(entropy)))
247-
randPool.Put(entropy)
248-
249-
return id
237+
return ULID(ulid.MustNew(ulid.Timestamp(time.Now()), rand.Reader))
250238
}
251239

252240
// NewULIDFromText creates a new ULID from its string representation. Will

0 commit comments

Comments
 (0)