diff options
Diffstat (limited to 'src/pkg/math/rand/example_test.go')
-rw-r--r-- | src/pkg/math/rand/example_test.go | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/pkg/math/rand/example_test.go b/src/pkg/math/rand/example_test.go index 4fe207d85..f42991453 100644 --- a/src/pkg/math/rand/example_test.go +++ b/src/pkg/math/rand/example_test.go @@ -11,12 +11,40 @@ import ( "text/tabwriter" ) -// This test serves as an example but also makes sure we don't change +// These tests serve as an example but also make sure we don't change // the output of the random number generator when given a fixed seed. +func Example() { + rand.Seed(42) // Try changing this number! + answers := []string{ + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes definitely", + "You may rely on it", + "As I see it yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes", + "Reply hazy try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", + "Don't count on it", + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful", + } + fmt.Println("Magic 8-Ball says:", answers[rand.Intn(len(answers))]) + // Output: Magic 8-Ball says: As I see it yes +} + // This example shows the use of each of the methods on a *Rand. // The use of the global functions is the same, without the receiver. -func Example() { +func Example_rand() { // Create and seed the generator. // Typically a non-fixed seed should be used, such as time.Now().UnixNano(). // Using a fixed seed will produce the same output on every run. |