-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.go
48 lines (39 loc) · 937 Bytes
/
random.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
package croot
// #include "croot/croot.h"
//
import "C"
import (
"unsafe"
)
// TRandom
type Random interface {
Object
Gaus(mean, sigma float64) float64
Rannorf() (a, b float32)
Rannord() (a, b float64)
Rndm(i int) float64
}
type randomImpl struct {
c C.CRoot_Random
}
var GRandom Random = &randomImpl{C.CRoot_gRandom}
func (r *randomImpl) Gaus(mean, sigma float64) float64 {
val := C.CRoot_Random_Gaus(r.c, C.double(mean), C.double(sigma))
return float64(val)
}
func (r *randomImpl) Rannorf() (a, b float32) {
ca := (*C.float)(unsafe.Pointer(&a))
cb := (*C.float)(unsafe.Pointer(&b))
C.CRoot_Random_Rannorf(r.c, ca, cb)
return
}
func (r *randomImpl) Rannord() (a, b float64) {
ca := (*C.double)(unsafe.Pointer(&a))
cb := (*C.double)(unsafe.Pointer(&b))
C.CRoot_Random_Rannord(r.c, ca, cb)
return
}
func (r *randomImpl) Rndm(i int) float64 {
val := C.CRoot_Random_Rndm(r.c, C.int32_t(i))
return float64(val)
}