File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1212package random
1313
1414import (
15+ "math"
16+ "math/rand"
17+
1518 "github.com/antithesishq/antithesis-sdk-go/internal"
1619)
1720
1821// GetRandom returns a uint64 value chosen by Antithesis. You should not store this value or use it to seed a PRNG, but should use it immediately.
1922func GetRandom () uint64 {
2023 return internal .Get_random ()
2124}
25+
26+ var _ rand.Source64 = source {}
27+
28+ type source struct {}
29+
30+ func (source ) Seed (int64 ) {}
31+
32+ func (source ) Int63 () int64 {
33+ return int64 (internal .Get_random () & (math .MaxUint64 >> 1 ))
34+ }
35+
36+ func (source ) Uint64 () uint64 {
37+ return internal .Get_random ()
38+ }
39+
40+ // NewSource initialises a source of pseudo-random data.
41+ //
42+ // Use this function to create a [math/rand.Rand] which provides feedback to the Antithesis platform.
43+ // Outside of Antithesis this is equivalent to calling [math/rand.NewSource].
44+ //
45+ // The returned source implements [math/rand.Source64].
46+ func NewSource (seed int64 ) rand.Source {
47+ return source {}
48+ }
Original file line number Diff line number Diff line change 99func GetRandom () uint64 {
1010 return rand .Uint64 ()
1111}
12+
13+ func NewSource (seed int64 ) rand.Source {
14+ return rand .NewSource (seed )
15+ }
You can’t perform that action at this time.
0 commit comments