我需要在每次执行应用程序时启动相同的随机数列表.
srand / rand不再存在了.那我该怎么办?
srand / rand不再存在了.那我该怎么办?
private extension Array { private func randomValues(_ seed: UInt32,num: Int) -> [Element] { srand (seed) var indices = [Int]() indices.reserveCapacity(num) let range = 0..<self.count for _ in 0..<num { var random = 0 repeat { random = randomNumberInRange(range) } while indices.contains(random) indices.append(random) } return indices.map { self[$0] } }
您可以使用 Swift3中的srand48(种子)和drand48().
原文链接:https://www.f2er.com/swift/318981.html