package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
var (
count int32
mutex sync.Mutex
)
func main() {
PrintN(100)
}
//PrintN PrintN
func PrintN(n int) {
var syn sync.WaitGroup
syn.Add(n)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
var array = make([]int, n+1)
for i := 1; i <= n; i++ {
go func() {
for {
mutex.Lock()
randn := r.Intn(n) + 1 if array[randn] == 0 {
array[randn] = 1
mutex.Unlock()
fmt.Println(randn)
syn.Done()
break
}
mutex.Unlock()
}
}()
}
syn.Wait()
}