title: go routine: does select really pick a random case?
body: <p>Context: <a href="https://tour.golang.org/concurrency/5" rel="nofollow noreferrer">https://tour.golang.org/concurrency/5</a></p>
  
  <p>Hello everyone, I am learning Go following the above link. </p>
  
  <p>The description says "It chooses one at random if multiple are ready."
  However, after making the main routine waiting for 2 second, before calling func fibonacci. The channels should be the following after 2 sec:
  c: 10 calls to get value from the channel
  quit: 0</p>
  
  <p>It looks to me both channels are ready. If "It chooses one at random if multiple are ready" is true, then there is a 50% chance that the first call on the case in fibonacci will get the 0 from the quit channel. However, it is not the case. All 10 numbers will always get printed out before quitting. Hence it does not look like the selection is random. Am I missing something?</p>
  
  <pre><code>package main
  
  import "fmt"
  import "time"
  
  func fibonacci(c, quit chan int) {
      x, y := 0, 1
      for {
          select {
          case c &lt;- x:
              x, y = y, x+y
          case &lt;-quit:
              fmt.Println("quit")
              return
          }
      }
  }
  
  func main() {
      c := make(chan int)
      quit := make(chan int)
      go func() {
          for i := 0; i &lt; 10; i++ {
              fmt.Println(&lt;-c)
          }
          quit &lt;- 0
      }()
      time.Sleep(2 * time.Second)
      fibonacci(c, quit)
  }
  </code></pre>
  
  <p>In addition, the next page:
  <a href="https://tour.golang.org/concurrency/6" rel="nofollow noreferrer">https://tour.golang.org/concurrency/6</a> </p>
  
  <p>It looks like the default code should print out either tick. or BOOM! at 500 milli second. However, only BOOM! is printed, always. If I changed the time in the default from 50 to 55, then both tick and BOOM get printed. Why is this? Does a After take precedence over a Tick in a select?</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "time"
  )
  
  func main() {
      tick := time.Tick(100 * time.Millisecond)
      boom := time.After(500 * time.Millisecond)
      for {
          select {
          case &lt;-tick:
              fmt.Println("tick.")
          case &lt;-boom:
              fmt.Println("BOOM!")
              return
          default:
              fmt.Println("    .")
              time.Sleep(55 * time.Millisecond)
          }
      }
  }
  </code></pre>