6 Star 28 Fork 14

Julia语言程序设计 / bookexamples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
count_heads.jl 325 Bytes
一键复制 编辑 原始数据 按行查看 历史
魏坤 提交于 2018-08-18 11:48 . 适配v1.0
function count_heads(n)
c::Int = 0 # 计数器
for i = 1:n # 投掷n次
c += rand(Bool) # 生成Bool型随机值,隐式转换为Int型,并将true作为1记录到变量c
end
c # 函数返回统计的true的数量,即为头像一面的数量
end
Julia
1
https://gitee.com/juliaprog/bookexamples.git
git@gitee.com:juliaprog/bookexamples.git
juliaprog
bookexamples
bookexamples
master

搜索帮助