我想以编程方式使用Apple的新Swift语言从viewController移动到另一个.我用Google搜索并阅读了文档,我看到了如何使用单个ViewController.有没有人有关于如何在视图控制器之间切换的示例或文档?
TL:博士; 如何生成随机数,因为书中的方法每次都会选择相同的数字.
根据Apple发布的书,这似乎是Swift生成随机数的方式.
protocol RandomNumberGenerator {
func random() -> Double
}
class LinearCongruentialGenerator: RandomNumberGenerator {
var lastRandom = 42.0
let m = 139968.0
let a = 3877.0
let c = 29573.0
func random() -> Double {
lastRandom = ((lastRandom * a + c) % m)
return lastRandom / m
}
}
let generator = LinearCongruentialGenerator()
for _ in 1..10 {
// Generate "random" number from 1-10
println(Int(generator.random() * 10)+1)
}
Run Code Online (Sandbox Code Playgroud)
问题是,在我放在底部的for循环中,输出如下所示:
4
8
7
8
6
2
6
4
1 …Run Code Online (Sandbox Code Playgroud)