1 Star 1 Fork 0

湖底观景/GolangTraining

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 587 Bytes
一键复制 编辑 原始数据 按行查看 历史
GoesToEleven 提交于 2017-02-01 22:44 +08:00 . you're doing great
package main
import (
"fmt"
"math/rand"
"sync"
)
const numFactorials = 100
const rdLimit = 20
func main() {
var w sync.WaitGroup
w.Add(numFactorials)
factorial(&w)
w.Wait()
}
func factorial(wmain *sync.WaitGroup) {
var w sync.WaitGroup
rand.Seed(42)
w.Add(numFactorials + 1)
for j := 1; j <= numFactorials; j++ {
go func() {
f := rand.Intn(rdLimit)
w.Wait()
total := 1
for i := f; i > 0; i-- {
total *= i
}
fmt.Println(f, total)
(*wmain).Done()
//out <- total
}()
w.Done()
}
fmt.Println("All done with initialization")
w.Done()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjianGood/GolangTraining.git
git@gitee.com:zhangjianGood/GolangTraining.git
zhangjianGood
GolangTraining
GolangTraining
afa19f5c43f3

搜索帮助