-
Notifications
You must be signed in to change notification settings - Fork 8
/
rand.go
38 lines (31 loc) · 1.1 KB
/
rand.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
package axon
import (
"cogentcore.org/core/vgpu/gosl/slrand"
)
//gosl:hlsl axonrand
// #include "slrand.hlsl"
//gosl:end axonrand
//gosl:start axonrand
type RandFunIndex uint32
// We use this enum to store a unique index for each function that
// requires random number generation. If you add a new function, you need to add
// a new enum entry here.
// RandFunIndexN is the total number of random functions. It autoincrements due to iota.
const (
RandFunActPGe RandFunIndex = iota
RandFunActPGi
RandFunActSMaintP
RandFunIndexN
)
// GetRandomNumber returns a random number that depends on the index, counter and function index.
// We increment the counter after each cycle, so that we get new random numbers.
// This whole scheme exists to ensure equal results under different multithreading settings.
func GetRandomNumber(index uint32, counter slrand.Counter, funIndex RandFunIndex) float32 {
// todo: gpu needs to have the shortcut to work directly on uint2
var randCtr slrand.Counter
randCtr = counter
randCtr.Add(uint32(funIndex))
ctr := randCtr.Uint2()
return slrand.Float(&ctr, index)
}
//gosl:end axonrand