github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/src/math/rand/race_test.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rand 6 7 import ( 8 "sync" 9 "testing" 10 ) 11 12 // TestConcurrent exercises the rand API concurrently, triggering situations 13 // where the race detector is likely to detect issues. 14 func TestConcurrent(t *testing.T) { 15 const ( 16 numRoutines = 10 17 numCycles = 10 18 ) 19 var wg sync.WaitGroup 20 defer wg.Wait() 21 wg.Add(numRoutines) 22 for i := 0; i < numRoutines; i++ { 23 go func(i int) { 24 defer wg.Done() 25 buf := make([]byte, 997) 26 for j := 0; j < numCycles; j++ { 27 var seed int64 28 seed += int64(ExpFloat64()) 29 seed += int64(Float32()) 30 seed += int64(Float64()) 31 seed += int64(Intn(Int())) 32 seed += int64(Int31n(Int31())) 33 seed += int64(Int63n(Int63())) 34 seed += int64(NormFloat64()) 35 seed += int64(Uint32()) 36 seed += int64(Uint64()) 37 for _, p := range Perm(10) { 38 seed += int64(p) 39 } 40 Read(buf) 41 for _, b := range buf { 42 seed += int64(b) 43 } 44 Seed(int64(i*j) * seed) 45 } 46 }(i) 47 } 48 }