@@ -7,14 +7,6 @@
77
88import Foundation
99
10−func getRandomNum(_ min: Int, _ max: Int) -> Int {
11− #if os(Linux)
12− return Int(random() % max) + min
13− #else
14− return Int(arc4random_uniform(UInt32(max)) + UInt32(min))
15− #endif
16−}
17−
1810struct SafeDict<Key: Hashable, Value> {
1911 private var queue = DispatchQueue(label: "soy.iko.safeDict.queue", attributes: .concurrent)
2012
@@ -41,9 +33,9 @@ struct SafeDict<Key: Hashable, Value> {
4133 mutating func removeRandom() -> Key? {
4234 var key: Key?
4335 queue.sync(flags: .barrier) {
44− if dict.count > 0 {
45− key = Array(dict.keys)[getRandomNum(0, dict.count)]
46− dict[key!] = nil
36+ key = dict.keys.randomElement()
37+ if let key = key {
38+ dict[key] = nil
4739 }
4840 }
4941 return key