mirror of
https://github.com/go-gitea/gitea
synced 2024-11-09 19:54:25 +00:00
ac97ea573c
* Update go-redis to v8.4.0 * github.com/go-redis/redis/v8 v8.4.0 -> v8.5.0 * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * TODO * Use the Queue termination channel as the default context for pushes Signed-off-by: Andrew Thornton <art27@cantab.net> * missed one Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
46 lines
1.1 KiB
Go
Vendored
46 lines
1.1 KiB
Go
Vendored
package rand
|
|
|
|
import (
|
|
"math/rand"
|
|
"sync"
|
|
)
|
|
|
|
// Int returns a non-negative pseudo-random int.
|
|
func Int() int { return pseudo.Int() }
|
|
|
|
// Intn returns, as an int, a non-negative pseudo-random number in [0,n).
|
|
// It panics if n <= 0.
|
|
func Intn(n int) int { return pseudo.Intn(n) }
|
|
|
|
// Int63n returns, as an int64, a non-negative pseudo-random number in [0,n).
|
|
// It panics if n <= 0.
|
|
func Int63n(n int64) int64 { return pseudo.Int63n(n) }
|
|
|
|
// Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n).
|
|
func Perm(n int) []int { return pseudo.Perm(n) }
|
|
|
|
// Seed uses the provided seed value to initialize the default Source to a
|
|
// deterministic state. If Seed is not called, the generator behaves as if
|
|
// seeded by Seed(1).
|
|
func Seed(n int64) { pseudo.Seed(n) }
|
|
|
|
var pseudo = rand.New(&source{src: rand.NewSource(1)})
|
|
|
|
type source struct {
|
|
src rand.Source
|
|
mu sync.Mutex
|
|
}
|
|
|
|
func (s *source) Int63() int64 {
|
|
s.mu.Lock()
|
|
n := s.src.Int63()
|
|
s.mu.Unlock()
|
|
return n
|
|
}
|
|
|
|
func (s *source) Seed(seed int64) {
|
|
s.mu.Lock()
|
|
s.src.Seed(seed)
|
|
s.mu.Unlock()
|
|
}
|