func randomInRange(range:Range<Int>) -> Int {
let count = UInt32(range.upperBound - range.lowerBound)
return Int(arc4random_uniform(count)) + range.lowerBound
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for _ in 0...100 {
print(randomInRange(range:Range.init(1...6)))
}
}
// 打印结果:3
6
3
1
3
6
2
3
2
6
1
4
5
4
4
6
6
1
1
5
3
1
2
6
1
6
5
4
2
1
4
3
1
4
2
1
2
3
4
2
5
4
2
6
6
5
4
3
6
6
5
4
2
1
2
2
1
4
3
5
2
1
2
2
6
3
2
3
2
1
1
2
6
4
3
4
3
4
1
2
6
6
3
4
5
4
3
1
1
6
6
5
1
5
4
5
4
6
5
5
1
arc4random_uniform
最新推荐文章于 2023-01-18 08:07:01 发布