package main

import (
	"fmt"
	"math/rand"
)

func PrintNumbers() {
	const IN_CHAN_NUM = 2
	numCh := make(chan int, 20)
	completeCh := make(chan int)
	defer close(numCh)
	defer close(completeCh)
	for i := 0; i < IN_CHAN_NUM; i++ {
		go func() {
			for j := 0; j < 10; j++ {
				numCh <- (rand.Int() % 100)
			}
		}()
	}
	go func() {
		i := 0
		for num := range numCh {
			fmt.Println(num)
			i++
			if i == 20 {
				break
			}
		}
		completeCh <- 1
	}()
	select {
	case <-completeCh:
	}
}

func main() {
	PrintNumbers()
}
