diff options
author | Russ Cox <rsc@golang.org> | 2023-08-05 23:49:01 -0400 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-10-30 14:29:37 +0000 |
commit | d42750b17c17fb1c3241b74c7ba2af96dff10195 (patch) | |
tree | 8b1e33dfc62b0f1f919f4141030cd08cb216b235 | |
parent | 59f0ab40369e4f05276aa2afe20a74beb78aa0b0 (diff) | |
download | go-d42750b17c17fb1c3241b74c7ba2af96dff10195.tar.gz go-d42750b17c17fb1c3241b74c7ba2af96dff10195.zip |
math/rand/v2: rename various functions
Int31 -> Int32
Int31n -> Int32N
Int63 -> Int64
Int63n -> Int64N
Intn -> IntN
The 31 and 63 are pedantic and confusing: the functions should
be named for the type they return, same as all the others.
The lower-case n is inconsistent with Go's usual CamelCase
and especially problematic because we plan to add 'func N'.
Capitalize the n.
For #61716.
Change-Id: Idb1a005a82f353677450d47fb612ade7a41fde69
Reviewed-on: https://go-review.googlesource.com/c/go/+/516857
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r-- | api/next/61716.txt | 28 | ||||
-rw-r--r-- | src/math/rand/v2/auto_test.go | 4 | ||||
-rw-r--r-- | src/math/rand/v2/example_test.go | 36 | ||||
-rw-r--r-- | src/math/rand/v2/export_test.go | 2 | ||||
-rw-r--r-- | src/math/rand/v2/race_test.go | 6 | ||||
-rw-r--r-- | src/math/rand/v2/rand.go | 96 | ||||
-rw-r--r-- | src/math/rand/v2/rand_test.go | 30 | ||||
-rw-r--r-- | src/math/rand/v2/regress_test.go | 209 | ||||
-rw-r--r-- | src/math/rand/v2/rng.go | 4 |
9 files changed, 209 insertions, 206 deletions
diff --git a/api/next/61716.txt b/api/next/61716.txt index d552934c43..36252ab50d 100644 --- a/api/next/61716.txt +++ b/api/next/61716.txt @@ -2,11 +2,11 @@ pkg math/rand/v2, func ExpFloat64() float64 #61716 pkg math/rand/v2, func Float32() float32 #61716 pkg math/rand/v2, func Float64() float64 #61716 pkg math/rand/v2, func Int() int #61716 -pkg math/rand/v2, func Int31() int32 #61716 -pkg math/rand/v2, func Int31n(int32) int32 #61716 -pkg math/rand/v2, func Int63() int64 #61716 -pkg math/rand/v2, func Int63n(int64) int64 #61716 -pkg math/rand/v2, func Intn(int) int #61716 +pkg math/rand/v2, func Int32() int32 #61716 +pkg math/rand/v2, func Int32N(int32) int32 #61716 +pkg math/rand/v2, func Int64() int64 #61716 +pkg math/rand/v2, func Int64N(int64) int64 #61716 +pkg math/rand/v2, func IntN(int) int #61716 pkg math/rand/v2, func New(Source) *Rand #61716 pkg math/rand/v2, func NewSource(int64) Source #61716 pkg math/rand/v2, func NewZipf(*Rand, float64, float64, uint64) *Zipf #61716 @@ -23,11 +23,11 @@ pkg math/rand/v2, method (*Rand) ExpFloat64() float64 #61716 pkg math/rand/v2, method (*Rand) Float32() float32 #61716 pkg math/rand/v2, method (*Rand) Float64() float64 #61716 pkg math/rand/v2, method (*Rand) Int() int #61716 -pkg math/rand/v2, method (*Rand) Int31() int32 #61716 -pkg math/rand/v2, method (*Rand) Int31n(int32) int32 #61716 -pkg math/rand/v2, method (*Rand) Int63() int64 #61716 -pkg math/rand/v2, method (*Rand) Int63n(int64) int64 #61716 -pkg math/rand/v2, method (*Rand) Intn(int) int #61716 +pkg math/rand/v2, method (*Rand) Int32() int32 #61716 +pkg math/rand/v2, method (*Rand) Int32N(int32) int32 #61716 +pkg math/rand/v2, method (*Rand) Int64() int64 #61716 +pkg math/rand/v2, method (*Rand) Int64N(int64) int64 #61716 +pkg math/rand/v2, method (*Rand) IntN(int) int #61716 pkg math/rand/v2, method (*Rand) NormFloat64() float64 #61716 pkg math/rand/v2, method (*Rand) Perm(int) []int #61716 pkg math/rand/v2, method (*Rand) Read([]uint8) (int, error) #61716 @@ -37,11 +37,11 @@ pkg math/rand/v2, method (*Rand) Uint32() uint32 #61716 pkg math/rand/v2, method (*Rand) Uint64() uint64 #61716 pkg math/rand/v2, method (*Zipf) Uint64() uint64 #61716 pkg math/rand/v2, type Rand struct #61716 -pkg math/rand/v2, type Source interface { Int63, Seed } #61716 -pkg math/rand/v2, type Source interface, Int63() int64 #61716 +pkg math/rand/v2, type Source interface { Int64, Seed } #61716 +pkg math/rand/v2, type Source interface, Int64() int64 #61716 pkg math/rand/v2, type Source interface, Seed(int64) #61716 -pkg math/rand/v2, type Source64 interface { Int63, Seed, Uint64 } #61716 -pkg math/rand/v2, type Source64 interface, Int63() int64 #61716 +pkg math/rand/v2, type Source64 interface { Int64, Seed, Uint64 } #61716 +pkg math/rand/v2, type Source64 interface, Int64() int64 #61716 pkg math/rand/v2, type Source64 interface, Seed(int64) #61716 pkg math/rand/v2, type Source64 interface, Uint64() uint64 #61716 pkg math/rand/v2, type Zipf struct #61716 diff --git a/src/math/rand/v2/auto_test.go b/src/math/rand/v2/auto_test.go index 92217ab0ee..ad6cd8bdae 100644 --- a/src/math/rand/v2/auto_test.go +++ b/src/math/rand/v2/auto_test.go @@ -19,7 +19,7 @@ func TestAuto(t *testing.T) { // order in the deterministic Seed(1) result. var out []int64 for i := 0; i < 10; i++ { - out = append(out, Int63()) + out = append(out, Int64()) } // Look for out in Seed(1)'s output. @@ -29,7 +29,7 @@ func TestAuto(t *testing.T) { Seed(1) found := 0 for i := 0; i < 1000; i++ { - x := Int63() + x := Int64() if x == out[found] { found++ if found == len(out) { diff --git a/src/math/rand/v2/example_test.go b/src/math/rand/v2/example_test.go index 03bbe32aeb..4bf4c50a74 100644 --- a/src/math/rand/v2/example_test.go +++ b/src/math/rand/v2/example_test.go @@ -38,7 +38,7 @@ func Example() { "Outlook not so good", "Very doubtful", } - fmt.Println("Magic 8-Ball says:", answers[rand.Intn(len(answers))]) + fmt.Println("Magic 8-Ball says:", answers[rand.IntN(len(answers))]) } // This example shows the use of each of the methods on a *Rand. @@ -66,18 +66,18 @@ func Example_rand() { // NormFloat64 values have an average of 0 and a standard deviation of 1. show("NormFloat64", r.NormFloat64(), r.NormFloat64(), r.NormFloat64()) - // Int31, Int63, and Uint32 generate values of the given width. - // The Int method (not shown) is like either Int31 or Int63 + // Int32, Int64, and Uint32 generate values of the given width. + // The Int method (not shown) is like either Int32 or Int64 // depending on the size of 'int'. - show("Int31", r.Int31(), r.Int31(), r.Int31()) - show("Int63", r.Int63(), r.Int63(), r.Int63()) + show("Int32", r.Int32(), r.Int32(), r.Int32()) + show("Int64", r.Int64(), r.Int64(), r.Int64()) show("Uint32", r.Uint32(), r.Uint32(), r.Uint32()) - // Intn, Int31n, and Int63n limit their output to be < n. + // IntN, Int32N, and Int64N limit their output to be < n. // They do so more carefully than using r.Int()%n. - show("Intn(10)", r.Intn(10), r.Intn(10), r.Intn(10)) - show("Int31n(10)", r.Int31n(10), r.Int31n(10), r.Int31n(10)) - show("Int63n(10)", r.Int63n(10), r.Int63n(10), r.Int63n(10)) + show("IntN(10)", r.IntN(10), r.IntN(10), r.IntN(10)) + show("Int32N(10)", r.Int32N(10), r.Int32N(10), r.Int32N(10)) + show("Int64N(10)", r.Int64N(10), r.Int64N(10), r.Int64N(10)) // Perm generates a random permutation of the numbers [0, n). show("Perm", r.Perm(5), r.Perm(5), r.Perm(5)) @@ -86,12 +86,12 @@ func Example_rand() { // Float64 0.628605430454327 0.4504798828572669 0.9562755949377957 // ExpFloat64 0.3362240648200941 1.4256072328483647 0.24354758816173044 // NormFloat64 0.17233959114940064 1.577014951434847 0.04259129641113857 - // Int31 1501292890 1486668269 182840835 - // Int63 3546343826724305832 5724354148158589552 5239846799706671610 + // Int32 1501292890 1486668269 182840835 + // Int64 3546343826724305832 5724354148158589552 5239846799706671610 // Uint32 2760229429 296659907 1922395059 - // Intn(10) 1 2 5 - // Int31n(10) 4 7 8 - // Int63n(10) 7 6 3 + // IntN(10) 1 2 5 + // Int32N(10) 4 7 8 + // Int64N(10) 7 6 3 // Perm [1 4 2 3 0] [4 2 1 3 0] [1 2 4 0 3] } @@ -126,8 +126,8 @@ func ExampleShuffle_slicesInUnison() { } } -func ExampleIntn() { - fmt.Println(rand.Intn(100)) - fmt.Println(rand.Intn(100)) - fmt.Println(rand.Intn(100)) +func ExampleIntN() { + fmt.Println(rand.IntN(100)) + fmt.Println(rand.IntN(100)) + fmt.Println(rand.IntN(100)) } diff --git a/src/math/rand/v2/export_test.go b/src/math/rand/v2/export_test.go index 560010be6b..f77ba9d4db 100644 --- a/src/math/rand/v2/export_test.go +++ b/src/math/rand/v2/export_test.go @@ -4,7 +4,7 @@ package rand -func Int31nForTest(r *Rand, n int32) int32 { +func Int32NForTest(r *Rand, n int32) int32 { return r.int31n(n) } diff --git a/src/math/rand/v2/race_test.go b/src/math/rand/v2/race_test.go index d164e7b428..d164f5024b 100644 --- a/src/math/rand/v2/race_test.go +++ b/src/math/rand/v2/race_test.go @@ -29,9 +29,9 @@ func TestConcurrent(t *testing.T) { seed += int64(ExpFloat64()) seed += int64(Float32()) seed += int64(Float64()) - seed += int64(Intn(Int())) - seed += int64(Int31n(Int31())) - seed += int64(Int63n(Int63())) + seed += int64(IntN(Int())) + seed += int64(Int32N(Int32())) + seed += int64(Int64N(Int64())) seed += int64(NormFloat64()) seed += int64(Uint32()) seed += int64(Uint64()) diff --git a/src/math/rand/v2/rand.go b/src/math/rand/v2/rand.go index 8979f68763..ed3bfe2e18 100644 --- a/src/math/rand/v2/rand.go +++ b/src/math/rand/v2/rand.go @@ -29,7 +29,7 @@ import ( // // A Source is not safe for concurrent use by multiple goroutines. type Source interface { - Int63() int64 + Int64() int64 Seed(seed int64) } @@ -38,7 +38,7 @@ type Source interface { // the range [0, 1<<64) directly. // If a Rand r's underlying Source s implements Source64, // then r.Uint64 returns the result of one call to s.Uint64 -// instead of making two calls to s.Int63. +// instead of making two calls to s.Int64. type Source64 interface { Source Uint64() uint64 @@ -92,66 +92,66 @@ func (r *Rand) Seed(seed int64) { r.readPos = 0 } -// Int63 returns a non-negative pseudo-random 63-bit integer as an int64. -func (r *Rand) Int63() int64 { return r.src.Int63() } +// Int64 returns a non-negative pseudo-random 63-bit integer as an int64. +func (r *Rand) Int64() int64 { return r.src.Int64() } // Uint32 returns a pseudo-random 32-bit value as a uint32. -func (r *Rand) Uint32() uint32 { return uint32(r.Int63() >> 31) } +func (r *Rand) Uint32() uint32 { return uint32(r.Int64() >> 31) } // Uint64 returns a pseudo-random 64-bit value as a uint64. func (r *Rand) Uint64() uint64 { if r.s64 != nil { return r.s64.Uint64() } - return uint64(r.Int63())>>31 | uint64(r.Int63())<<32 + return uint64(r.Int64())>>31 | uint64(r.Int64())<<32 } -// Int31 returns a non-negative pseudo-random 31-bit integer as an int32. -func (r *Rand) Int31() int32 { return int32(r.Int63() >> 32) } +// Int32 returns a non-negative pseudo-random 31-bit integer as an int32. +func (r *Rand) Int32() int32 { return int32(r.Int64() >> 32) } // Int returns a non-negative pseudo-random int. func (r *Rand) Int() int { - u := uint(r.Int63()) + u := uint(r.Int64()) return int(u << 1 >> 1) // clear sign bit if int == int32 } -// Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n). +// Int64N returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n). // It panics if n <= 0. -func (r *Rand) Int63n(n int64) int64 { +func (r *Rand) Int64N(n int64) int64 { if n <= 0 { - panic("invalid argument to Int63n") + panic("invalid argument to Int64N") } if n&(n-1) == 0 { // n is power of two, can mask - return r.Int63() & (n - 1) + return r.Int64() & (n - 1) } max := int64((1 << 63) - 1 - (1<<63)%uint64(n)) - v := r.Int63() + v := r.Int64() for v > max { - v = r.Int63() + v = r.Int64() } return v % n } -// Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n). +// Int32N returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n). // It panics if n <= 0. -func (r *Rand) Int31n(n int32) int32 { +func (r *Rand) Int32N(n int32) int32 { if n <= 0 { - panic("invalid argument to Int31n") + panic("invalid argument to Int32N") } if n&(n-1) == 0 { // n is power of two, can mask - return r.Int31() & (n - 1) + return r.Int32() & (n - 1) } max := int32((1 << 31) - 1 - (1<<31)%uint32(n)) - v := r.Int31() + v := r.Int32() for v > max { - v = r.Int31() + v = r.Int32() } return v % n } // int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n). // n must be > 0, but int31n does not check this; the caller must ensure it. -// int31n exists because Int31n is inefficient, but Go 1 compatibility +// int31n exists because Int32N is inefficient, but Go 1 compatibility // requires that the stream of values produced by math/rand/v2 remain unchanged. // int31n can thus only be used internally, by newly introduced APIs. // @@ -173,27 +173,27 @@ func (r *Rand) int31n(n int32) int32 { return int32(prod >> 32) } -// Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n). +// IntN returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n). // It panics if n <= 0. -func (r *Rand) Intn(n int) int { +func (r *Rand) IntN(n int) int { if n <= 0 { - panic("invalid argument to Intn") + panic("invalid argument to IntN") } if n <= 1<<31-1 { - return int(r.Int31n(int32(n))) + return int(r.Int32N(int32(n))) } - return int(r.Int63n(int64(n))) + return int(r.Int64N(int64(n))) } // Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0). func (r *Rand) Float64() float64 { // A clearer, simpler implementation would be: - // return float64(r.Int63n(1<<53)) / (1<<53) + // return float64(r.Int64N(1<<53)) / (1<<53) // However, Go 1 shipped with - // return float64(r.Int63()) / (1 << 63) + // return float64(r.Int64()) / (1 << 63) // and we want to preserve that value stream. // - // There is one bug in the value stream: r.Int63() may be so close + // There is one bug in the value stream: r.Int64() may be so close // to 1<<63 that the division rounds up to 1.0, and we've guaranteed // that the result is always less than 1.0. // @@ -204,7 +204,7 @@ func (r *Rand) Float64() float64 { // Getting 1 only happens 1/2⁵³ of the time, so most clients // will not observe it anyway. again: - f := float64(r.Int63()) / (1 << 63) + f := float64(r.Int64()) / (1 << 63) if f == 1 { goto again // resample; this branch is taken O(never) } @@ -234,7 +234,7 @@ func (r *Rand) Perm(n int) []int { // the final state of r. So this change can't be made for compatibility // reasons for Go 1. for i := 0; i < n; i++ { - j := r.Intn(i + 1) + j := r.IntN(i + 1) m[i] = m[j] m[j] = i } @@ -257,7 +257,7 @@ func (r *Rand) Shuffle(n int, swap func(i, j int)) { // Nevertheless, the right API signature accepts an int n, so handle it as best we can. i := n - 1 for ; i > 1<<31-1-1; i-- { - j := int(r.Int63n(int64(i + 1))) + j := int(r.Int64N(int64(i + 1))) swap(i, j) } for ; i > 0; i-- { @@ -286,9 +286,9 @@ func read(p []byte, src Source, readVal *int64, readPos *int8) (n int, err error for n = 0; n < len(p); n++ { if pos == 0 { if rng != nil { - val = rng.Int63() + val = rng.Int64() } else { - val = src.Int63() + val = src.Int64() } pos = 7 } @@ -356,7 +356,7 @@ type fastSource struct { mu sync.Mutex } -func (*fastSource) Int63() int64 { +func (*fastSource) Int64() int64 { return int64(fastrand64() & rngMask) } @@ -418,9 +418,9 @@ func Seed(seed int64) { } } -// Int63 returns a non-negative pseudo-random 63-bit integer as an int64 +// Int64 returns a non-negative pseudo-random 63-bit integer as an int64 // from the default Source. -func Int63() int64 { return globalRand().Int63() } +func Int64() int64 { return globalRand().Int64() } // Uint32 returns a pseudo-random 32-bit value as a uint32 // from the default Source. @@ -430,27 +430,27 @@ func Uint32() uint32 { return globalRand().Uint32() } // from the default Source. func Uint64() uint64 { return globalRand().Uint64() } -// Int31 returns a non-negative pseudo-random 31-bit integer as an int32 +// Int32 returns a non-negative pseudo-random 31-bit integer as an int32 // from the default Source. -func Int31() int32 { return globalRand().Int31() } +func Int32() int32 { return globalRand().Int32() } // Int returns a non-negative pseudo-random int from the default Source. func Int() int { return globalRand().Int() } -// Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n) +// Int64N returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n) // from the default Source. // It panics if n <= 0. -func Int63n(n int64) int64 { return globalRand().Int63n(n) } +func Int64N(n int64) int64 { return globalRand().Int64N(n) } -// Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n) +// Int32N returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n) // from the default Source. // It panics if n <= 0. -func Int31n(n int32) int32 { return globalRand().Int31n(n) } +func Int32N(n int32) int32 { return globalRand().Int32N(n) } -// Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n) +// IntN returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n) // from the default Source. // It panics if n <= 0. -func Intn(n int) int { return globalRand().Intn(n) } +func IntN(n int) int { return globalRand().IntN(n) } // Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0) // from the default Source. @@ -500,9 +500,9 @@ type lockedSource struct { s *rngSource } -func (r *lockedSource) Int63() (n int64) { +func (r *lockedSource) Int64() (n int64) { r.lk.Lock() - n = r.s.Int63() + n = r.s.Int64() r.lk.Unlock() return } diff --git a/src/math/rand/v2/rand_test.go b/src/math/rand/v2/rand_test.go index 27368719ff..c1da833e07 100644 --- a/src/math/rand/v2/rand_test.go +++ b/src/math/rand/v2/rand_test.go @@ -507,8 +507,8 @@ func TestUniformFactorial(t *testing.T) { name string fn func() int }{ - {name: "Int31n", fn: func() int { return int(r.Int31n(int32(nfact))) }}, - {name: "int31n", fn: func() int { return int(Int31nForTest(r, int32(nfact))) }}, + {name: "Int32N", fn: func() int { return int(r.Int32N(int32(nfact))) }}, + {name: "int31n", fn: func() int { return int(Int32NForTest(r, int32(nfact))) }}, {name: "Perm", fn: func() int { return encodePerm(r.Perm(n)) }}, {name: "Shuffle", fn: func() int { // Generate permutation using Shuffle. @@ -564,45 +564,45 @@ func TestUniformFactorial(t *testing.T) { // Benchmarks -func BenchmarkInt63Threadsafe(b *testing.B) { +func BenchmarkInt64Threadsafe(b *testing.B) { for n := b.N; n > 0; n-- { - Int63() + Int64() } } -func BenchmarkInt63ThreadsafeParallel(b *testing.B) { +func BenchmarkInt64ThreadsafeParallel(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - Int63() + Int64() } }) } -func BenchmarkInt63Unthreadsafe(b *testing.B) { +func BenchmarkInt64Unthreadsafe(b *testing.B) { r := New(NewSource(1)) for n := b.N; n > 0; n-- { - r.Int63() + r.Int64() } } -func BenchmarkIntn1000(b *testing.B) { +func BenchmarkIntN1000(b *testing.B) { r := New(NewSource(1)) for n := b.N; n > 0; n-- { - r.Intn(1000) + r.IntN(1000) } } -func BenchmarkInt63n1000(b *testing.B) { +func BenchmarkInt64N1000(b *testing.B) { r := New(NewSource(1)) for n := b.N; n > 0; n-- { - r.Int63n(1000) + r.Int64N(1000) } } -func BenchmarkInt31n1000(b *testing.B) { +func BenchmarkInt32N1000(b *testing.B) { r := New(NewSource(1)) for n := b.N; n > 0; n-- { - r.Int31n(1000) + r.Int32N(1000) } } @@ -693,7 +693,7 @@ func BenchmarkConcurrent(b *testing.B) { go func() { defer wg.Done() for n := b.N; n > 0; n-- { - Int63() + Int64() } }() } diff --git a/src/math/rand/v2/regress_test.go b/src/math/rand/v2/regress_test.go index bfc910871a..ee0c8da586 100644 --- a/src/math/rand/v2/regress_test.go +++ b/src/math/rand/v2/regress_test.go @@ -58,7 +58,10 @@ func TestRegress(t *testing.T) { } big := int64s[repeat%len(int64s)] if int64(int(big)) != big { - r.Int63n(big) // what would happen on 64-bit machine, to keep stream in sync + // On 32-bit machine. + // Consume an Int64 like on a 64-bit machine, + // to keep the golden data the same on different architectures. + r.Int64N(big) if *printgolden { fmt.Printf("\tskipped, // must run printgolden on 64-bit machine\n") } @@ -85,7 +88,7 @@ func TestRegress(t *testing.T) { var out any out = mv.Call(args)[0].Interface() - if m.Name == "Int" || m.Name == "Intn" { + if m.Name == "Int" || m.Name == "IntN" { out = int64(out.(int)) } if m.Name == "Read" { @@ -94,7 +97,7 @@ func TestRegress(t *testing.T) { if *printgolden { var val string big := int64(1 << 60) - if int64(int(big)) != big && (m.Name == "Int" || m.Name == "Intn") { + if int64(int(big)) != big && (m.Name == "Int" || m.Name == "IntN") { // 32-bit machine cannot print 64-bit results val = "truncated" } else if reflect.TypeOf(out).Kind() == reflect.Slice { @@ -201,106 +204,106 @@ var regressGolden = []any{ int64(161231572858529631), // Int() int64(7259475919510918339), // Int() int64(7373105480197164748), // Int() - int32(2029793274), // Int31() - int32(526058514), // Int31() - int32(1408655353), // Int31() - int32(116702506), // Int31() - int32(789387515), // Int31() - int32(621654496), // Int31() - int32(413258767), // Int31() - int32(1407315077), // Int31() - int32(1926657288), // Int31() - int32(359390928), // Int31() - int32(619732968), // Int31() - int32(1938329147), // Int31() - int32(1824889259), // Int31() - int32(586363548), // Int31() - int32(1307989752), // Int31() - int32(544722126), // Int31() - int32(1663557311), // Int31() - int32(37539650), // Int31() - int32(1690228450), // Int31() - int32(1716684894), // Int31() - int32(0), // Int31n(1) - int32(4), // Int31n(10) - int32(25), // Int31n(32) - int32(310570), // Int31n(1048576) - int32(857611), // Int31n(1048577) - int32(621654496), // Int31n(1000000000) - int32(413258767), // Int31n(1073741824) - int32(1407315077), // Int31n(2147483646) - int32(1926657288), // Int31n(2147483647) - int32(0), // Int31n(1) - int32(8), // Int31n(10) - int32(27), // Int31n(32) - int32(367019), // Int31n(1048576) - int32(209005), // Int31n(1048577) - int32(307989752), // Int31n(1000000000) - int32(544722126), // Int31n(1073741824) - int32(1663557311), // Int31n(2147483646) - int32(37539650), // Int31n(2147483647) - int32(0), // Int31n(1) - int32(4), // Int31n(10) - int64(8717895732742165505), // Int63() - int64(2259404117704393152), // Int63() - int64(6050128673802995827), // Int63() - int64(501233450539197794), // Int63() - int64(3390393562759376202), // Int63() - int64(2669985732393126063), // Int63() - int64(1774932891286980153), // Int63() - int64(6044372234677422456), // Int63() - int64(8274930044578894929), // Int63() - int64(1543572285742637646), // Int63() - int64(2661732831099943416), // Int63() - int64(8325060299420976708), // Int63() - int64(7837839688282259259), // Int63() - int64(2518412263346885298), // Int63() - int64(5617773211005988520), // Int63() - int64(2339563716805116249), // Int63() - int64(7144924247938981575), // Int63() - int64(161231572858529631), // Int63() - int64(7259475919510918339), // Int63() - int64(7373105480197164748), // Int63() - int64(0), // Int63n(1) - int64(2), // Int63n(10) - int64(19), // Int63n(32) - int64(959842), // Int63n(1048576) - int64(688912), // Int63n(1048577) - int64(393126063), // Int63n(1000000000) - int64(89212473), // Int63n(1073741824) - int64(834026388), // Int63n(2147483646) - int64(1577188963), // Int63n(2147483647) - int64(543572285742637646), // Int63n(1000000000000000000) - int64(355889821886249464), // Int63n(1152921504606846976) - int64(8325060299420976708), // Int63n(9223372036854775806) - int64(7837839688282259259), // Int63n(9223372036854775807) - int64(0), // Int63n(1) - int64(0), // Int63n(10) - int64(25), // Int63n(32) - int64(679623), // Int63n(1048576) - int64(882178), // Int63n(1048577) - int64(510918339), // Int63n(1000000000) - int64(782454476), // Int63n(1073741824) - int64(0), // Intn(1) - int64(4), // Intn(10) - int64(25), // Intn(32) - int64(310570), // Intn(1048576) - int64(857611), // Intn(1048577) - int64(621654496), // Intn(1000000000) - int64(413258767), // Intn(1073741824) - int64(1407315077), // Intn(2147483646) - int64(1926657288), // Intn(2147483647) - int64(543572285742637646), // Intn(1000000000000000000) - int64(355889821886249464), // Intn(1152921504606846976) - int64(8325060299420976708), // Intn(9223372036854775806) - int64(7837839688282259259), // Intn(9223372036854775807) - int64(0), // Intn(1) - int64(2), // Intn(10) - int64(14), // Intn(32) - int64(515775), // Intn(1048576) - int64(839455), // Intn(1048577) - int64(690228450), // Intn(1000000000) - int64(642943070), // Intn(1073741824) + int32(2029793274), // Int32() + int32(526058514), // Int32() + int32(1408655353), // Int32() + int32(116702506), // Int32() + int32(789387515), // Int32() + int32(621654496), // Int32() + int32(413258767), // Int32() + int32(1407315077), // Int32() + int32(1926657288), // Int32() + int32(359390928), // Int32() + int32(619732968), // Int32() + int32(1938329147), // Int32() + int32(1824889259), // Int32() + int32(586363548), // Int32() + int32(1307989752), // Int32() + int32(544722126), // Int32() + int32(1663557311), // Int32() + int32(37539650), // Int32() + int32(1690228450), // Int32() + int32(1716684894), // Int32() + int32(0), // Int32N(1) + int32(4), // Int32N(10) + int32(25), // Int32N(32) + int32(310570), // Int32N(1048576) + int32(857611), // Int32N(1048577) + int32(621654496), // Int32N(1000000000) + int32(413258767), // Int32N(1073741824) + int32(1407315077), // Int32N(2147483646) + int32(1926657288), // Int32N(2147483647) + int32(0), // Int32N(1) + int32(8), // Int32N(10) + int32(27), // Int32N(32) + int32(367019), // Int32N(1048576) + int32(209005), // Int32N(1048577) + int32(307989752), // Int32N(1000000000) + int32(544722126), // Int32N(1073741824) + int32(1663557311), // Int32N(2147483646) + int32(37539650), // Int32N(2147483647) + int32(0), // Int32N(1) + int32(4), // Int32N(10) + int64(8717895732742165505), // Int64() + int64(2259404117704393152), // Int64() + int64(6050128673802995827), // Int64() + int64(501233450539197794), // Int64() + int64(3390393562759376202), // Int64() + int64(2669985732393126063), // Int64() + int64(1774932891286980153), // Int64() + int64(6044372234677422456), // Int64() + int64(8274930044578894929), // Int64() + int64(1543572285742637646), // Int64() + int64(2661732831099943416), // Int64() + int64(8325060299420976708), // Int64() + int64(7837839688282259259), // Int64() + int64(2518412263346885298), // Int64() + int64(5617773211005988520), // Int64() + int64(2339563716805116249), // Int64() + int64(7144924247938981575), // Int64() + int64(161231572858529631), // Int64() + int64(7259475919510918339), // Int64() + int64(7373105480197164748), // Int64() + int64(0), // Int64N(1) + int64(2), // Int64N(10) + int64(19), // Int64N(32) + int64(959842), // Int64N(1048576) + int64(688912), // Int64N(1048577) + int64(393126063), // Int64N(1000000000) + int64(89212473), // Int64N(1073741824) + int64(834026388), // Int64N(2147483646) + int64(1577188963), // Int64N(2147483647) + int64(543572285742637646), // Int64N(1000000000000000000) + int64(355889821886249464), // Int64N(1152921504606846976) + int64(8325060299420976708), // Int64N(9223372036854775806) + int64(7837839688282259259), // Int64N(9223372036854775807) + int64(0), // Int64N(1) + int64(0), // Int64N(10) + int64(25), // Int64N(32) + int64(679623), // Int64N(1048576) + int64(882178), // Int64N(1048577) + int64(510918339), // Int64N(1000000000) + int64(782454476), // Int64N(1073741824) + int64(0), // IntN(1) + int64(4), // IntN(10) + int64(25), // IntN(32) + int64(310570), // IntN(1048576) + int64(857611), // IntN(1048577) + int64(621654496), // IntN(1000000000) + int64(413258767), // IntN(1073741824) + int64(1407315077), // IntN(2147483646) + int64(1926657288), // IntN(2147483647) + int64(543572285742637646), // IntN(1000000000000000000) + int64(355889821886249464), // IntN(1152921504606846976) + int64(8325060299420976708), // IntN(9223372036854775806) + int64(7837839688282259259), // IntN(9223372036854775807) + int64(0), // IntN(1) + int64(2), // IntN(10) + int64(14), // IntN(32) + int64(515775), // IntN(1048576) + int64(839455), // IntN(1048577) + int64(690228450), // IntN(1000000000) + int64(642943070), // IntN(1073741824) float64(-0.28158587086436215), // NormFloat64() float64(0.570933095808067), // NormFloat64() float64(-1.6920196326157044), // NormFloat64() diff --git a/src/math/rand/v2/rng.go b/src/math/rand/v2/rng.go index 1e4a9e014f..841957e8fd 100644 --- a/src/math/rand/v2/rng.go +++ b/src/math/rand/v2/rng.go @@ -229,8 +229,8 @@ func (rng *rngSource) Seed(seed int64) { } } -// Int63 returns a non-negative pseudo-random 63-bit integer as an int64. -func (rng *rngSource) Int63() int64 { +// Int64 returns a non-negative pseudo-random 63-bit integer as an int64. +func (rng *rngSource) Int64() int64 { return int64(rng.Uint64() & rngMask) } |