-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint64.go
43 lines (34 loc) · 889 Bytes
/
int64.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
package chance
import "math"
// Int64Option is a type
type Int64Option func(*Int64Options)
// Int64Options is int64 options
type Int64Options struct {
min int64
max int64
}
func (ch *chance) Int64(options ...Int64Option) int64 {
ops := Int64Options{min: -math.MaxInt64 / 2, max: math.MaxInt64 / 2} // FIXME: Use full range
for i := range options {
options[i](&ops)
}
ch.r.Seed(ch.seed)
// TODO: handle error on bad options
return ch.r.Int63n(ops.max-ops.min) + ops.min
}
// Int64 returns a random int64
func Int64(options ...Int64Option) int64 {
return defaultChance.Int64(options...)
}
// SetInt64Min sets min of random int64
func SetInt64Min(min int64) Int64Option {
return func(iOpts *Int64Options) {
iOpts.min = min
}
}
// SetInt64Max sets max of random int64
func SetInt64Max(max int64) Int64Option {
return func(iOpts *Int64Options) {
iOpts.max = max
}
}