-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.go
40 lines (24 loc) · 792 Bytes
/
math.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
// App Core functions and vars | Math
// @help:
// fmt.Printf("LeadingZeros64(%064b) = %d\n", 1, bits.LeadingZeros64(1))
// https://golang.org/pkg/math/bits/#LeadingZeros64
package core
import (
"math/rand"
"sync/atomic"
)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |structs|
// Инкрементальный счётчик для многопоточных задач
func AtomicAdd(sum *uint64, delta uint64) uint64 {
return atomic.AddUint64(sum, delta)
}
// Random
func RandInt64() int64 {
//rand.Seed(time.Now().UTC().UnixNano())
//return rand.Int63n(math.MaxInt64)
return rand.Int63()
}
// Random from min to max
func Rand(min, max int64) int64 {
return rand.Int63n(max - min) + min
}