Unpredicted output using go routines

package main

import (
“fmt”
“sync”
)

var wg sync.WaitGroup

func main() {
wg.Add(2)

go func(){
	fmt.Println("Hello form one")
	wg.Done()
}()

go func(){
	fmt.Println("Hello form two")
	wg.Done()
}()

wg.Wait()

}

by running the following program.
Why does “Hello form two” prints first the “Hello from one”.

The Go Programming Language Specification

Go statements

A “go” statement starts the execution of a function call as an independent concurrent thread of control, or goroutine , within the same address space.

The Go runtime scheduler runs the goroutines concurrently in a pseudorandom, fair fashion.

Since you can’t predict the throw of a fair dice, you will have to try loading the dice. For example,

package main

import (
	"fmt"
	"runtime"
	"sync"
)

var wg sync.WaitGroup

func main() {
	runtime.GOMAXPROCS(1)

	wg.Add(2)

	go func() {
		fmt.Println("Hello form one")
		wg.Done()
	}()

	runtime.Gosched()

	go func() {
		fmt.Println("Hello form two")
		wg.Done()
	}()

	wg.Wait()
}

https://play.golang.org/p/qIvyemPQBU5

Hello form one
Hello form two

The last go is at the next scheduled position.