forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template2.go
36 lines (26 loc) · 1.1 KB
/
template2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// Write a program that uses a fan out pattern to generate 100 random numbers
// concurrently. Have each goroutine generate a single random number and return
// that number to the main goroutine over a buffered channel. Set the size of
// the buffer channel so no send every blocks. Don't allocate more buffers than
// you need. Have the main goroutine display each random number is receives and
// then terminate the program.
package main
// Add imports.
// Declare constant for number of goroutines .
func init() {
// Seed the random number generator.
}
func main() {
// Create the buffer channel with a buffer for
// each goroutine to be created.
// Iterate and launch each goroutine.
{
// Create an anonymous function for each goroutine that
// generates a random number and sends it on the channel.
}
// Create a variable to be used to track received messages.
// Set the value to the number of goroutines created.
// Iterate receiving each value until they are all received.
}