Debian Codegraph @

common/dice/dice.go

raw symbols SCIP
1 // Package dice contains common functions to generate random number.
2 // It also initialize math/rand with the time in seconds at launch time.
3 package dicescip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/ // import "v2ray.com/core/common/dice"
4
5 import (
6 "math/randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/"
7 "timescip-go gomod github.com/golang/go/src go1.15 time/"
8 )
9
10 // Roll returns a non-negative number between 0 (inclusive) and n (exclusive).
11 func Rollscip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/Roll().(n int) int {
12 if n == 1 {
13 return 0
14 }
15 return randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.15 `math/rand`/Intn().(n)
16 }
17
18 // Roll returns a non-negative number between 0 (inclusive) and n (exclusive).
19 func RollDeterministicscip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/RollDeterministic().(n int, seed int64) int {
20 if n == 1 {
21 return 0
22 }
23 return randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.15 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.15 `math/rand`/NewSource().(seed)).Intnscip-go gomod github.com/golang/go/src go1.15 `math/rand`/Rand#Intn().(n)
24 }
25
26 // RollUint16 returns a random uint16 value.
27 func RollUint16scip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/RollUint16().() uint16 {
28 return uint16(randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.Int63scip-go gomod github.com/golang/go/src go1.15 `math/rand`/Int63().() >> 47)
29 }
30
31 func RollUint64scip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/RollUint64().() uint64 {
32 return randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.Uint64scip-go gomod github.com/golang/go/src go1.15 `math/rand`/Uint64().()
33 }
34
35 func NewDeterministicDicescip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/NewDeterministicDice().(seed int64) *DeterministicDicescip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/DeterministicDice# {
36 return &DeterministicDicescip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/DeterministicDice#{randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.15 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.15 `math/rand`/NewSource().(seed))}
37 }
38
39 type DeterministicDicescip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/DeterministicDice# struct {
40 *randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.Randscip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/DeterministicDice#Rand.
41 }
42
43 func (dd *DeterministicDicescip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/DeterministicDice#) Rollscip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/DeterministicDice#Roll().(n int) int {
44 if n == 1 {
45 return 0
46 }
47 return dd.Intnscip-go gomod github.com/golang/go/src go1.15 `math/rand`/Rand#Intn().(n)
48 }
49
50 func initscip-go gomod v2ray.com/core . `v2ray.com/core/common/dice`/init().() {
51 randscip-go gomod github.com/golang/go/src go1.15 `math/rand`/.Seedscip-go gomod github.com/golang/go/src go1.15 `math/rand`/Seed().(timescip-go gomod github.com/golang/go/src go1.15 time/.Nowscip-go gomod github.com/golang/go/src go1.15 time/Now().().Unixscip-go gomod github.com/golang/go/src go1.15 time/Time#Unix().())
52 }