forked from lightstep/lightstep-tracer-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
32 lines (26 loc) · 814 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package lightstep
import (
"runtime"
"time"
"github.com/lightstep/lightstep-tracer-go/lightstep/rand"
)
var (
// create a random pool with size equal to 16 generators or number of CPU Cores which ever is higher to spread
// random int call loads across multiple go routines. This number is obtained via local benchmarking
// where any number more than 16 reaches a point of diminishing return given the test scenario.
randompool = rand.NewPool(time.Now().UnixNano(), uint64(max(16, runtime.NumCPU())))
)
// max returns the larger value among a and b
func max(x, y int) int {
if x > y {
return x
}
return y
}
func genSeededGUID() uint64 {
return uint64(randompool.Pick().Int63())
}
func genSeededGUID2() (uint64, uint64) {
n1, n2 := randompool.Pick().TwoInt63()
return uint64(n1), uint64(n2)
}