Skip to content

Commit

Permalink
adds DefaultEntropy docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pastuxso committed Nov 1, 2023
1 parent f566f43 commit 3791e7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/utils/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var (
entropyOnce sync.Once
)

// DefaultEntropy returns a reader that generates ULID entropy.
// The default entropy function utilizes math/rand.Rand, which is not safe for concurrent use by multiple goroutines.
// Therefore, this function employs x/exp/rand, as recommended by the authors of the library.
func DefaultEntropy() io.Reader {
entropyOnce.Do(func() {
seed := uint64(time.Now().UnixNano())
Expand All @@ -32,9 +35,9 @@ func DefaultEntropy() io.Reader {
// IsULID checks if the given string is a valid ULID
// ULID pattern:
//
// 01AN4Z07BY 79KA1307SR9X4MV3
// 01AN4Z07BY 79KA1307SR9X4MV3
// |----------| |----------------|
// Timestamp Randomness
// Timestamp Randomness
//
// 10 characters 16 characters
// Crockford's Base32 is used (excludes I, L, O, and U to avoid confusion and abuse)
Expand Down

0 comments on commit 3791e7e

Please sign in to comment.