Skip to content

Commit

Permalink
math/rand: document that NewSource sources race
Browse files Browse the repository at this point in the history
While it was previously explicitly documented that "the default Source"
is safe for concurrent use, a careless reader can interpret that as
meaning "the implementation of the Source interface created by functions
in this package" rather than "the default shared Source used by
top-level functions". Be explicit that the Source returned by NewSource
is not safe for use by multiple goroutines.

Fixes #3611.

Change-Id: Iae4bc04c3887ad6e2491e36e38feda40324022c5
Reviewed-on: https://go-review.googlesource.com/25501
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
glasser authored and bradfitz committed Sep 2, 2016
1 parent 98def53 commit 82bc0d4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/math/rand/rand.go
Expand Up @@ -24,6 +24,8 @@ type Source interface {
}

// NewSource returns a new pseudo-random Source seeded with the given value.
// Unlike the default Source used by top-level functions, this source is not
// safe for concurrent use by multiple goroutines.
func NewSource(seed int64) Source {
var rng rngSource
rng.Seed(seed)
Expand Down

0 comments on commit 82bc0d4

Please sign in to comment.