我试图制作四个不同的变量,使a和b不同,a和c不同,b和c不同等等。以下是四个变量。
CUSTOMER_TBL
答案 0 :(得分:6)
尽管问题已经得到解答,但这是另一种解决方案:
var set = Set<UInt32>()
while set.count < 4 {
set.insert(arc4random_uniform(5))
}
答案 1 :(得分:5)
let a = Int(arc4random_uniform(5))
var b = Int(arc4random_uniform(5))
while b == a {
b = Int(arc4random_uniform(5))
}
var c = Int(arc4random_uniform(5))
while c == a || c == b {
c = Int(arc4random_uniform(5))
}
var d = Int(arc4random_uniform(5))
while d == c || d == b || d == a {
d = Int(arc4random_uniform(5))
}
println(a) // 2
println(b) // 0
println(c) // 4
println(d) // 3