diff --git a/base/randx/rand.go b/base/randx/rand.go index 560cae91..f19ea531 100644 --- a/base/randx/rand.go +++ b/base/randx/rand.go @@ -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) @@ -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)) diff --git a/base/randx/typegen.go b/base/randx/typegen.go index 32ddeddb..98087add 100644 --- a/base/randx/typegen.go +++ b/base/randx/typegen.go @@ -6,12 +6,12 @@ import ( "cogentcore.org/core/types" ) -var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/base/randx.Rand", IDName: "rand", Doc: "Rand provides an interface with most of the standard\nrand.Rand methods, to support the use of either the\nglobal rand generator or a separate Rand source.", Methods: []types.Method{{Name: "Seed", Doc: "Seed uses the provided seed value to initialize the generator to a deterministic state.\nSeed should not be called concurrently with any other Rand method.", Args: []string{"seed"}}, {Name: "Int63", Doc: "Int63 returns a non-negative pseudo-random 63-bit integer as an int64.", Returns: []string{"int64"}}, {Name: "Uint32", Doc: "Uint32 returns a pseudo-random 32-bit value as a uint32.", Returns: []string{"uint32"}}, {Name: "Uint64", Doc: "Uint64 returns a pseudo-random 64-bit value as a uint64.", Returns: []string{"uint64"}}, {Name: "Int31", Doc: "Int31 returns a non-negative pseudo-random 31-bit integer as an int32.", Returns: []string{"int32"}}, {Name: "Int", Doc: "Int returns a non-negative pseudo-random int.", Returns: []string{"int"}}, {Name: "Int63n", Doc: "Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n).\nIt panics if n <= 0.", Args: []string{"n"}, Returns: []string{"int64"}}, {Name: "Int31n", Doc: "Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n).\nIt panics if n <= 0.", Args: []string{"n"}, Returns: []string{"int32"}}, {Name: "Intn", Doc: "Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n).\nIt panics if n <= 0.", Args: []string{"n"}, Returns: []string{"int"}}, {Name: "Float64", Doc: "Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).", Returns: []string{"float64"}}, {Name: "Float32", Doc: "Float32 returns, as a float32, a pseudo-random number in the half-open interval [0.0,1.0).", Returns: []string{"float32"}}, {Name: "NormFloat64", Doc: "NormFloat64 returns a normally distributed float64 in the range\n[-math.MaxFloat64, +math.MaxFloat64] with\nstandard normal distribution (mean = 0, stddev = 1)\nfrom the default Source.\nTo produce a different normal distribution, callers can\nadjust the output using:\n\n\tsample = NormFloat64() * desiredStdDev + desiredMean", Returns: []string{"float64"}}, {Name: "ExpFloat64", Doc: "ExpFloat64 returns an exponentially distributed float64 in the range\n(0, +math.MaxFloat64] with an exponential distribution whose rate parameter\n(lambda) is 1 and whose mean is 1/lambda (1) from the default Source.\nTo produce a distribution with a different rate parameter,\ncallers can adjust the output using:\n\n\tsample = ExpFloat64() / desiredRateParameter", Returns: []string{"float64"}}, {Name: "Perm", Doc: "Perm returns, as a slice of n ints, a pseudo-random permutation of the integers\nin the half-open interval [0,n).", Args: []string{"n"}, Returns: []string{"[]int"}}, {Name: "Shuffle", Doc: "Shuffle pseudo-randomizes the order of elements.\nn is the number of elements. Shuffle panics if n < 0.\nswap swaps the elements with indexes i and j.", Args: []string{"n", "swap"}}}}) +var _ = types.AddType(&types.Type{Name: "cogentcore.org/lab/base/randx.Rand", IDName: "rand", Doc: "Rand provides an interface with most of the standard\nrand.Rand methods, to support the use of either the\nglobal rand generator or a separate Rand source.", Methods: []types.Method{{Name: "Init", Doc: "Init initializes this random source with given seed, ensuring\nthat there is a Rand object in place if not already, and\nthen calling Seed with given value.", Args: []string{"seed"}}, {Name: "Seed", Doc: "Seed uses the provided seed value to initialize the generator to a deterministic state.\nSeed should not be called concurrently with any other Rand method.", Args: []string{"seed"}}, {Name: "Int63", Doc: "Int63 returns a non-negative pseudo-random 63-bit integer as an int64.", Returns: []string{"int64"}}, {Name: "Uint32", Doc: "Uint32 returns a pseudo-random 32-bit value as a uint32.", Returns: []string{"uint32"}}, {Name: "Uint64", Doc: "Uint64 returns a pseudo-random 64-bit value as a uint64.", Returns: []string{"uint64"}}, {Name: "Int31", Doc: "Int31 returns a non-negative pseudo-random 31-bit integer as an int32.", Returns: []string{"int32"}}, {Name: "Int", Doc: "Int returns a non-negative pseudo-random int.", Returns: []string{"int"}}, {Name: "Int63n", Doc: "Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n).\nIt panics if n <= 0.", Args: []string{"n"}, Returns: []string{"int64"}}, {Name: "Int31n", Doc: "Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n).\nIt panics if n <= 0.", Args: []string{"n"}, Returns: []string{"int32"}}, {Name: "Intn", Doc: "Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n).\nIt panics if n <= 0.", Args: []string{"n"}, Returns: []string{"int"}}, {Name: "Float64", Doc: "Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).", Returns: []string{"float64"}}, {Name: "Float32", Doc: "Float32 returns, as a float32, a pseudo-random number in the half-open interval [0.0,1.0).", Returns: []string{"float32"}}, {Name: "NormFloat64", Doc: "NormFloat64 returns a normally distributed float64 in the range\n[-math.MaxFloat64, +math.MaxFloat64] with\nstandard normal distribution (mean = 0, stddev = 1)\nfrom the default Source.\nTo produce a different normal distribution, callers can\nadjust the output using:\n\n\tsample = NormFloat64() * desiredStdDev + desiredMean", Returns: []string{"float64"}}, {Name: "ExpFloat64", Doc: "ExpFloat64 returns an exponentially distributed float64 in the range\n(0, +math.MaxFloat64] with an exponential distribution whose rate parameter\n(lambda) is 1 and whose mean is 1/lambda (1) from the default Source.\nTo produce a distribution with a different rate parameter,\ncallers can adjust the output using:\n\n\tsample = ExpFloat64() / desiredRateParameter", Returns: []string{"float64"}}, {Name: "Perm", Doc: "Perm returns, as a slice of n ints, a pseudo-random permutation of the integers\nin the half-open interval [0,n).", Args: []string{"n"}, Returns: []string{"[]int"}}, {Name: "Shuffle", Doc: "Shuffle pseudo-randomizes the order of elements.\nn is the number of elements. Shuffle panics if n < 0.\nswap swaps the elements with indexes i and j.", Args: []string{"n", "swap"}}}}) -var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/base/randx.SysRand", IDName: "sys-rand", Doc: "SysRand supports the system random number generator\nfor either a separate rand.Rand source, or, if that\nis nil, the global rand stream.", Fields: []types.Field{{Name: "Rand", Doc: "if non-nil, use this random number source instead of the global default one"}}}) +var _ = types.AddType(&types.Type{Name: "cogentcore.org/lab/base/randx.SysRand", IDName: "sys-rand", Doc: "SysRand supports the system random number generator\nfor either a separate rand.Rand source, or, if that\nis nil, the global rand stream.", Fields: []types.Field{{Name: "Rand", Doc: "if non-nil, use this random number source instead of the global default one"}}}) -var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/base/randx.RandParams", IDName: "rand-params", Doc: "RandParams provides parameterized random number generation according to different distributions\nand variance, mean params", Directives: []types.Directive{{Tool: "git", Directive: "add"}}, Fields: []types.Field{{Name: "Dist", Doc: "distribution to generate random numbers from"}, {Name: "Mean", Doc: "mean of random distribution -- typically added to generated random variants"}, {Name: "Var", Doc: "variability parameter for the random numbers (gauss = standard deviation, not variance; uniform = half-range, others as noted in RandDists)"}, {Name: "Par", Doc: "extra parameter for distribution (depends on each one)"}}}) +var _ = types.AddType(&types.Type{Name: "cogentcore.org/lab/base/randx.RandParams", IDName: "rand-params", Doc: "RandParams provides parameterized random number generation according to different distributions\nand variance, mean params", Directives: []types.Directive{{Tool: "git", Directive: "add"}}, Fields: []types.Field{{Name: "Dist", Doc: "distribution to generate random numbers from"}, {Name: "Mean", Doc: "mean of random distribution -- typically added to generated random variants"}, {Name: "Var", Doc: "variability parameter for the random numbers (gauss = standard deviation, not variance; uniform = half-range, others as noted in RandDists)"}, {Name: "Par", Doc: "extra parameter for distribution (depends on each one)"}}}) -var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/base/randx.RandDists", IDName: "rand-dists", Doc: "RandDists are different random number distributions"}) +var _ = types.AddType(&types.Type{Name: "cogentcore.org/lab/base/randx.RandDists", IDName: "rand-dists", Doc: "RandDists are different random number distributions"}) -var _ = types.AddType(&types.Type{Name: "cogentcore.org/core/base/randx.Seeds", IDName: "seeds", Doc: "Seeds is a set of random seeds, typically used one per Run"}) +var _ = types.AddType(&types.Type{Name: "cogentcore.org/lab/base/randx.Seeds", IDName: "seeds", Doc: "Seeds is a set of random seeds, typically used one per Run"}) diff --git a/go.mod b/go.mod index a3569be3..4f18d148 100644 --- a/go.mod +++ b/go.mod @@ -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 ) @@ -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 diff --git a/go.sum b/go.sum index bf1295bb..4cfa8d87 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ codeberg.org/go-pdf/fpdf v0.11.0 h1:n3I8WISQ1cr0S2rvx9DOlE/GypbcimMWqLpel3slHmY= codeberg.org/go-pdf/fpdf v0.11.0/go.mod h1:Y0DGRAdZ0OmnZPvjbMp/1bYxmIPxm0ws4tfoPOc4LjU= -cogentcore.org/core v0.3.21 h1:IPxkRb/ibwXEWoyTr7jmUOky3HQkJeq10e3VL8dlih0= -cogentcore.org/core v0.3.21/go.mod h1:IQBEleZr+h6O/UjnymY875ve9kY0yokLK8YJ/JUPPBg= +cogentcore.org/core v0.3.22 h1:wKOzPgrRhX7qV7WWrDE68gJaJ/x50f5wWm79/rx50YQ= +cogentcore.org/core v0.3.22/go.mod h1:IQBEleZr+h6O/UjnymY875ve9kY0yokLK8YJ/JUPPBg= git.sr.ht/~sbinet/cmpimg v0.1.0 h1:E0zPRk2muWuCqSKSVZIWsgtU9pjsw3eKHi8VmQeScxo= git.sr.ht/~sbinet/cmpimg v0.1.0/go.mod h1:FU12psLbF4TfNXkKH2ZZQ29crIqoiqTZmeQ7dkp/pxE= github.com/Bios-Marcel/wastebasket/v2 v2.0.3 h1:TkoDPcSqluhLGE+EssHu7UGmLgUEkWg7kNyHyyJ3Q9g= @@ -127,52 +127,74 @@ go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8= go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM= +go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48= go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA= go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI= +go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0= go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E= go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg= +go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18= go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM= go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA= +go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8= go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE= go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs= +go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI= golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8= golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A= +golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= +golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= golang.org/x/exp v0.0.0-20260112195511-716be5621a96 h1:Z/6YuSHTLOHfNFdb8zVZomZr7cqNgTJvA8+Qz75D8gU= golang.org/x/exp v0.0.0-20260112195511-716be5621a96/go.mod h1:nzimsREAkjBCIEFtHiYkrJyT+2uy9YZJB7H1k68CXZU= golang.org/x/image v0.35.0 h1:LKjiHdgMtO8z7Fh18nGY6KDcoEtVfsgLDPeLyguqb7I= golang.org/x/image v0.35.0/go.mod h1:MwPLTVgvxSASsxdLzKrl8BRFuyqMyGhLwmC+TO1Sybk= golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c= golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU= +golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= +golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= +golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY= golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww= +golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= +golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= +golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto v0.0.0-20260226221140-a57be14db171 h1:RxhCsti413yL0IjU9dVvuTbCISo8gs3RW1jPMStck+4= -google.golang.org/genproto v0.0.0-20260226221140-a57be14db171/go.mod h1:uhvzakVEqAuXU3TC2JCsxIRe5f77l+JySE3EqPoMyqM= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260203192932-546029d2fa20 h1:Jr5R2J6F6qWyzINc+4AM8t5pfUz6beZpHp678GNrMbE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260203192932-546029d2fa20/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= +google.golang.org/genproto v0.0.0-20260401024825-9d38bb4040a9 h1:w8JYjr7zHemS95YA5FFwk+fUv5tdQU4I8twN9bFdxVU= +google.golang.org/genproto v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:YCEC8W7HTtK7iBv+pI7g7hGAi7qdGB6bQXw3BIYAusM= google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d h1:t/LOSXPJ9R0B6fnZNyALBRfZBH0Uy0gT+uR+SJ6syqQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260401001100-f93e5f3e9f0f h1:Rka45QInERYknkHYfJEPBQaoobXl+YpxTMjAKgWUq2A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260401001100-f93e5f3e9f0f/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc= google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U= +google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE= +google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/goal/goalib/goalib.go b/goal/goalib/goalib.go index 556abbc9..751b2fd4 100644 --- a/goal/goalib/goalib.go +++ b/goal/goalib/goalib.go @@ -34,6 +34,12 @@ func FileExists(path string) bool { return ex } +// DirExists returns true if given directory exists +func DirExists(path string) bool { + ex := errors.Log1(fsx.DirExists(path)) + return ex +} + // WriteFile writes string to given file with standard permissions, // logging any errors. func WriteFile(filename, str string) error { diff --git a/patterns/rand.go b/patterns/rand.go index 30f73e23..7f62944e 100644 --- a/patterns/rand.go +++ b/patterns/rand.go @@ -13,10 +13,10 @@ var ( // random numbers will be generated for all calls, and the seed is saved as // RandSeed. It can be reinstated by calling RestoreSeed. // Can also set RandSource to another existing randx.Rand source to use it. - RandSource = &randx.SysRand{} + RandSource randx.Rand = randx.NewSysRand(5711) - // Random seed last set by NewRand or SetRandSeed. - RandSeed int64 + // Random seed last set by NewRand or SetRandSeed (5711 by default). + RandSeed int64 = 5711 ) // NewRand sets RandSource to a new separate random number stream diff --git a/yaegilab/tensorsymbols/cogentcore_org-lab-goal-goalib.go b/yaegilab/tensorsymbols/cogentcore_org-lab-goal-goalib.go index d318a1d9..e3c60c8f 100644 --- a/yaegilab/tensorsymbols/cogentcore_org-lab-goal-goalib.go +++ b/yaegilab/tensorsymbols/cogentcore_org-lab-goal-goalib.go @@ -11,6 +11,7 @@ func init() { Symbols["cogentcore.org/lab/goal/goalib/goalib"] = map[string]reflect.Value{ // function, constant and variable definitions "AllFiles": reflect.ValueOf(goalib.AllFiles), + "DirExists": reflect.ValueOf(goalib.DirExists), "FileExists": reflect.ValueOf(goalib.FileExists), "ReadFile": reflect.ValueOf(goalib.ReadFile), "ReplaceInFile": reflect.ValueOf(goalib.ReplaceInFile),