Skip to content

Instantly share code, notes, and snippets.

@StareIntoTheBeard
Created May 12, 2014 17:21
Show Gist options
  • Save StareIntoTheBeard/e8184372736d1713b28a to your computer and use it in GitHub Desktop.
Save StareIntoTheBeard/e8184372736d1713b28a to your computer and use it in GitHub Desktop.
concurrency.go
package main
import (
"fmt"
"time"
"math/rand"
)
func f(n int) {
for i := 0; i < 10; i++ {
fmt.Println(n, ":", i)
amt := time.Duration(rand.Intn(250))
time.Sleep(time.Millisecond * amt)
}
}
func main() {
for i := 0; i < 10; i++ {
go f(i)
}
var input string
fmt.Scanln(&input)
}
@StareIntoTheBeard
Copy link
Author

0 : 0
1 : 0
2 : 0
3 : 0
4 : 0
5 : 0
6 : 0
7 : 0
8 : 0
9 : 0
8 : 1
0 : 1
4 : 1
0 : 2
6 : 1
1 : 1
5 : 1
3 : 1
1 : 2
2 : 1
0 : 3
7 : 1
9 : 1
4 : 2
4 : 3
9 : 2
8 : 2
2 : 2
8 : 3
4 : 4
5 : 2
3 : 2
4 : 5
6 : 2
8 : 4
5 : 3
1 : 3
6 : 3
2 : 3
7 : 2
0 : 4
7 : 3
9 : 3
4 : 6
5 : 4
3 : 3
8 : 5
4 : 7
7 : 4
6 : 4
0 : 5
4 : 8
8 : 6
1 : 4
3 : 4
3 : 5
6 : 5
2 : 4
5 : 5
9 : 4
2 : 5
7 : 5
7 : 6
9 : 5
6 : 6
8 : 7
6 : 7
0 : 6
1 : 5
7 : 7
4 : 9
3 : 6
1 : 6
1 : 7
5 : 6
6 : 8
8 : 8
2 : 6
9 : 6
8 : 9
6 : 9
3 : 7
0 : 7
5 : 7
7 : 8
1 : 8
2 : 7
1 : 9
2 : 8
0 : 8
0 : 9
9 : 7
3 : 8
5 : 8
3 : 9
9 : 8
9 : 9
2 : 9
5 : 9
7 : 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment