Skip to content

Commit 9a8979d

Browse files
cn0047bradfitz
authored andcommitted
math/rand: add example for Intn func
Change-Id: I831ffb5c3fa2872d71def8d8461f0adbd4ae2c1a GitHub-Last-Rev: 2adfcd2 GitHub-Pull-Request: golang#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>
1 parent 42cdc26 commit 9a8979d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/math/rand/example_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,18 @@ func ExampleShuffle_slicesInUnison() {
140140
// E: 5
141141
// B: 2
142142
}
143+
144+
func ExampleIntn() {
145+
// Seeding with the same value results in the same random sequence each run.
146+
// For different numbers, seed with a different value, such as
147+
// time.Now().UnixNano(), which yields a constantly-changing number.
148+
rand.Seed(86)
149+
fmt.Println(rand.Intn(100))
150+
fmt.Println(rand.Intn(100))
151+
fmt.Println(rand.Intn(100))
152+
153+
// Output:
154+
// 42
155+
// 76
156+
// 30
157+
}

0 commit comments

Comments
 (0)