-
Notifications
You must be signed in to change notification settings - Fork 1
/
fastplugin.go
67 lines (50 loc) · 993 Bytes
/
fastplugin.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package sgc7plugin
import (
"context"
"time"
"github.com/valyala/fastrand"
sgc7utils "github.com/zhs007/slotsgamecore7/utils"
)
// BasicPlugin - basic plugin
type FastPlugin struct {
PluginBase
RNG *fastrand.RNG
}
// NewFastPlugin - new a BasicPlugin
func NewFastPlugin() *FastPlugin {
fp := &FastPlugin{
PluginBase: NewPluginBase(),
RNG: &fastrand.RNG{},
}
fp.Init()
return fp
}
// Random - return [0, r)
func (fp *FastPlugin) Random(ctx context.Context, r int) (int, error) {
if IsNoRNGCache {
ci := int(fp.RNG.Uint32())
cr := ci % r
return cr, nil
}
var ci int
if len(fp.Cache) > 0 {
ci = fp.Cache[0]
fp.Cache = fp.Cache[1:]
} else {
ci = int(fp.RNG.Uint32())
}
cr := ci % r
fp.AddRngUsed(&sgc7utils.RngInfo{
Bits: cr,
Range: r,
Value: cr,
})
return cr, nil
}
// Init - initial
func (fp *FastPlugin) Init() {
fp.RNG.Seed(uint32(time.Now().UnixNano()))
}
// SetSeed - set a seed
func (fp *FastPlugin) SetSeed(seed int) {
}