Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions base/randx/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import "math/rand"
// rand.Rand methods, to support the use of either the
// global rand generator or a separate Rand source.
type Rand interface {
// Init initializes this random source with given seed, ensuring
// that there is a Rand object in place if not already, and
// then calling Seed with given value.
Init(seed int64)

// Seed uses the provided seed value to initialize the generator to a deterministic state.
// Seed should not be called concurrently with any other Rand method.
Seed(seed int64)
Expand Down Expand Up @@ -102,6 +107,28 @@ func NewSysRand(seed int64) *SysRand {
return r
}

// InitSysRand initializes the given pointer to a [randx.Rand]
// source to a new SysRand if it is nil, and otherwise calls
// Init on the existing one, all with given initial seed.
func InitSysRand(r *Rand, seed int64) {
if *r == nil {
*r = NewSysRand(seed)
} else {
(*r).Init(seed)
}
}

// Init initializes this random source with given seed, ensuring
// that there is a Rand object in place if not already, and
// then calling Seed with given value.
func (r *SysRand) Init(seed int64) {
if r.Rand == nil {
r.NewRand(seed)
return
}
r.Rand.Seed(seed)
}

// NewRand sets Rand to a new rand.Rand source using given seed.
func (r *SysRand) NewRand(seed int64) {
r.Rand = rand.New(rand.NewSource(seed))
Expand Down
10 changes: 5 additions & 5 deletions base/randx/typegen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ go 1.25.6
// https://github.com/googleapis/go-genproto/issues/1015

require (
cogentcore.org/core v0.3.21
cogentcore.org/core v0.3.22
github.com/cogentcore/readline v0.1.3
github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3
github.com/mitchellh/go-homedir v1.1.0
github.com/nsf/termbox-go v1.1.1
github.com/stretchr/testify v1.11.1
golang.org/x/exp v0.0.0-20260112195511-716be5621a96
golang.org/x/tools v0.41.0
golang.org/x/tools v0.42.0
gonum.org/v1/gonum v0.17.0
google.golang.org/grpc v1.78.0
google.golang.org/grpc v1.79.3
google.golang.org/protobuf v1.36.11
)

Expand Down Expand Up @@ -60,15 +60,15 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/tdewolff/parse/v2 v2.8.5 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/crypto v0.49.0 // indirect
golang.org/x/image v0.35.0 // indirect
golang.org/x/mod v0.32.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.33.0 // indirect
google.golang.org/genproto v0.0.0-20260226221140-a57be14db171 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/net v0.52.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.42.0 // indirect
golang.org/x/text v0.35.0 // indirect
google.golang.org/genproto v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401001100-f93e5f3e9f0f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/knuth v0.5.4 // indirect
modernc.org/token v1.1.0 // indirect
Expand Down
Loading
Loading