File: random.go

package info (click to toggle)
golang-github-opentracing-basictracer-go 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: makefile: 24
file content (20 lines) | stat: -rw-r--r-- 382 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package dapperish

import (
	"math/rand"
	"sync"
	"time"
)

var (
	seededIDGen  = rand.New(rand.NewSource(time.Now().UnixNano()))
	seededIDLock sync.Mutex
)

// Generate [UnixNano-seeded] pseudorandom numbers.
func randomID() int64 {
	// The golang rand generators are *not* intrinsically thread-safe.
	seededIDLock.Lock()
	defer seededIDLock.Unlock()
	return seededIDGen.Int63()
}