arc4random

xiaoxiao2021-02-28  55

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
转载请注明原文地址: https://www.6miu.com/read-2632495.html

最新回复(0)