-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmathrand.go
34 lines (27 loc) · 865 Bytes
/
mathrand.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
33
34
package randomkit
import (
"math/rand"
)
// RKMathRandSource is a wrapper to adapt RKState to math/rand
type RKMathRandSource struct{ RKState *RKState }
// AsMathRandSource return RKState as a source suitable for rand.New
func (state *RKState) AsMathRandSource() *RKMathRandSource {
return &RKMathRandSource{state}
}
// Seed proto for math/rand source
func (state *RKMathRandSource) Seed(seed int64) {
state.RKState.Seed(uint64(seed))
}
// Int63 for math/rand source
func (state *RKMathRandSource) Int63() int64 {
return state.RKState.Int63()
}
// Uint64 for math/rand source
func (state *RKMathRandSource) Uint64() uint64 {
return state.RKState.Uint64()
}
// Clone allow duplicating source state
func (state *RKMathRandSource) Clone() rand.Source {
newrkstate := *((state.RKState).Clone().(*RKState))
return &RKMathRandSource{RKState: &newrkstate}
}