gpt4 book ai didi

ios - 在Xcode 7.3.1 Playgrounds中正确绘制数组

转载 作者:行者123 更新时间:2023-12-01 20:12:40 25 4
gpt4 key购买 nike

我试图检查各种随机函数在Xcode中的分布情况,所以我创建了这个操场:

import UIKit
import XCPlayground

var distribution: [Int] = Array(count: 6, repeatedValue: 0)
for i in 1...100000 {
let randomNumber = arc4random_uniform(6)
distribution[Int(randomNumber)] += 1
XCPlaygroundPage.currentPage.captureValue(distribution[Int(randomNumber)], withIdentifier: "Random Distribution")
}

我希望看到的是沿着图表底部的一条线,描绘了正态分布(或平坦分布),但我得到了对角线。我如何使其达到水平?

最佳答案

您在收集值时正在捕获值,而需要最终值:

for i in 0..<6 {
XCPlaygroundPage.currentPage.captureValue(distribution[i], withIdentifier: "Distribution")
}

关于ios - 在Xcode 7.3.1 Playgrounds中正确绘制数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37466155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com