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

标签 ios plot swift-playground

我试图检查各种随机函数在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/

相关文章:

r - 强制将常规绘图对象放入 Grob 以在 grid.arrange 中使用

xcode - 更改默认的 Xcode Playground 代码

swift - iPad 上的 Playgrounds 因此代码而崩溃

ios - 如何使用swift Playground 为switch语句中的随机间隔分配概率?

ios - Objective-C 中的自定义构造函数

ios - AVPlayer 不播放本地 mp4

ios - 我可以序列化持有授权 Twitter 帐户的 ACAccount 对象吗?

ios - 检查字符串是否包含大于

r - 我可以将屏幕上的绘图写入文件吗?

r - 在 R 中从列表创建多个饼图