Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
23
Task/Concurrent-computing/Go/concurrent-computing-1.go
Normal file
23
Task/Concurrent-computing/Go/concurrent-computing-1.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang.org/x/exp/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
words := []string{"Enjoy", "Rosetta", "Code"}
|
||||
seed := uint64(time.Now().UnixNano())
|
||||
q := make(chan string)
|
||||
for i, w := range words {
|
||||
go func(w string, seed uint64) {
|
||||
r := rand.New(rand.NewSource(seed))
|
||||
time.Sleep(time.Duration(r.Int63n(1e9)))
|
||||
q <- w
|
||||
}(w, seed+uint64(i))
|
||||
}
|
||||
for i := 0; i < len(words); i++ {
|
||||
fmt.Println(<-q)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue