消息“不匹配任何可用的重载”是什么意思?
What does the message ' do not match any available overloads' mean?
在操场上,我尝试使用以下代码生成正态分布的随机数:
import UIKit
import GameplayKit
var mu: Double = 0
var random: Double = 0
for i in 1...1000 {
let random = GKRandomSource()
mu = GKGaussianDistribution(randomSource: random, mean: Float(0.0), distribution: Float(1.0))
print(mu)
}
这将无法编译,我收到以下错误消息:"Argument labels '(randomSource:, mean:, distribution:)' do not match any available overloads"
这是什么意思,我该如何更正代码?
您的代码有几个问题,参数称为 deviation
,而不是 distribution
,并且 Distribution 对象本身不是 return 随机数。
试试这个:
import GameplayKit
let random = GKRandomSource()
let dist = GKGaussianDistribution(randomSource: random, mean: 0, deviation: 1.0)
for _ in 1...1000 {
let mu = dist.nextUniform()
print(mu)
}
在操场上,我尝试使用以下代码生成正态分布的随机数:
import UIKit
import GameplayKit
var mu: Double = 0
var random: Double = 0
for i in 1...1000 {
let random = GKRandomSource()
mu = GKGaussianDistribution(randomSource: random, mean: Float(0.0), distribution: Float(1.0))
print(mu)
}
这将无法编译,我收到以下错误消息:"Argument labels '(randomSource:, mean:, distribution:)' do not match any available overloads"
这是什么意思,我该如何更正代码?
您的代码有几个问题,参数称为 deviation
,而不是 distribution
,并且 Distribution 对象本身不是 return 随机数。
试试这个:
import GameplayKit
let random = GKRandomSource()
let dist = GKGaussianDistribution(randomSource: random, mean: 0, deviation: 1.0)
for _ in 1...1000 {
let mu = dist.nextUniform()
print(mu)
}