mirror of https://github.com/golang/go.git
math/rand: add example for Intn func
Change-Id: I831ffb5c3fa2872d71def8d8461f0adbd4ae2c1a
GitHub-Last-Rev: 2adfcd2d5a
GitHub-Pull-Request: golang/go#30706
Reviewed-on: https://go-review.googlesource.com/c/go/+/166426
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
42cdc26665
commit
9a8979deb0
|
|
@ -140,3 +140,18 @@ func ExampleShuffle_slicesInUnison() {
|
|||
// E: 5
|
||||
// B: 2
|
||||
}
|
||||
|
||||
func ExampleIntn() {
|
||||
// Seeding with the same value results in the same random sequence each run.
|
||||
// For different numbers, seed with a different value, such as
|
||||
// time.Now().UnixNano(), which yields a constantly-changing number.
|
||||
rand.Seed(86)
|
||||
fmt.Println(rand.Intn(100))
|
||||
fmt.Println(rand.Intn(100))
|
||||
fmt.Println(rand.Intn(100))
|
||||
|
||||
// Output:
|
||||
// 42
|
||||
// 76
|
||||
// 30
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue