Add vendor directory and update vendorHash to null
This commit is contained in:
parent
523831cb8d
commit
1e5424c844
778 changed files with 407919 additions and 1 deletions
54
vendor/github.com/sethvargo/go-retry/rand.go
generated
vendored
Normal file
54
vendor/github.com/sethvargo/go-retry/rand.go
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package retry
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type lockedSource struct {
|
||||
src *rand.Rand
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
var _ rand.Source64 = (*lockedSource)(nil)
|
||||
|
||||
func newLockedRandom(seed int64) *lockedSource {
|
||||
return &lockedSource{src: rand.New(rand.NewSource(seed))}
|
||||
}
|
||||
|
||||
// Int63 mimics math/rand.(*Rand).Int63 with mutex locked.
|
||||
func (r *lockedSource) Int63() int64 {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.src.Int63()
|
||||
}
|
||||
|
||||
// Seed mimics math/rand.(*Rand).Seed with mutex locked.
|
||||
func (r *lockedSource) Seed(seed int64) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.src.Seed(seed)
|
||||
}
|
||||
|
||||
// Uint64 mimics math/rand.(*Rand).Uint64 with mutex locked.
|
||||
func (r *lockedSource) Uint64() uint64 {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.src.Uint64()
|
||||
}
|
||||
|
||||
// Int63n mimics math/rand.(*Rand).Int63n with mutex locked.
|
||||
func (r *lockedSource) Int63n(n int64) int64 {
|
||||
if n <= 0 {
|
||||
panic("invalid argument to Int63n")
|
||||
}
|
||||
if n&(n-1) == 0 { // n is power of two, can mask
|
||||
return r.Int63() & (n - 1)
|
||||
}
|
||||
max := int64((1 << 63) - 1 - (1<<63)%uint64(n))
|
||||
v := r.Int63()
|
||||
for v > max {
|
||||
v = r.Int63()
|
||||
}
|
||||
return v % n
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue