]> Cypherpunks repositories - gostls13.git/commitdiff
math/rand: add example for Intn func
authorVladimir Kovpak <cn007b@gmail.com>
Wed, 13 Mar 2019 09:39:21 +0000 (09:39 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 25 Mar 2019 16:05:37 +0000 (16:05 +0000)
Change-Id: I831ffb5c3fa2872d71def8d8461f0adbd4ae2c1a
GitHub-Last-Rev: 2adfcd2d5a592ef4c63da781240a391da89b5d9e
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>
src/math/rand/example_test.go

index adeeaa0b469ac71b3b968b51e77508b9521c587d..41076135558cbbda570321fe1d6261a77936bacc 100644 (file)
@@ -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
+}