...
Source file
src/math/rand/race_test.go
1
2
3
4
5 package rand_test
6
7 import (
8 . "math/rand"
9 "sync"
10 "testing"
11 )
12
13
14
15 func TestConcurrent(t *testing.T) {
16 const (
17 numRoutines = 10
18 numCycles = 10
19 )
20 var wg sync.WaitGroup
21 defer wg.Wait()
22 wg.Add(numRoutines)
23 for i := 0; i < numRoutines; i++ {
24 go func(i int) {
25 defer wg.Done()
26 buf := make([]byte, 997)
27 for j := 0; j < numCycles; j++ {
28 var seed int64
29 seed += int64(ExpFloat64())
30 seed += int64(Float32())
31 seed += int64(Float64())
32 seed += int64(Intn(Int()))
33 seed += int64(Int31n(Int31()))
34 seed += int64(Int63n(Int63()))
35 seed += int64(NormFloat64())
36 seed += int64(Uint32())
37 seed += int64(Uint64())
38 for _, p := range Perm(10) {
39 seed += int64(p)
40 }
41 Read(buf)
42 for _, b := range buf {
43 seed += int64(b)
44 }
45 Seed(int64(i*j) * seed)
46 }
47 }(i)
48 }
49 }
50
View as plain text