File tree Expand file tree Collapse file tree 2 files changed +6
-7
lines changed
Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -929,12 +929,12 @@ extension Collection {
929929 using generator: inout T
930930 ) -> Element ? {
931931 guard !isEmpty else { return nil }
932- let random = generator . next ( upperBound : UInt ( count) )
933- let index = self . index (
932+ let random = Int . random ( in : 0 ..< count)
933+ let idx = index (
934934 startIndex,
935- offsetBy: numericCast ( random)
935+ offsetBy: random
936936 )
937- return self [ index ]
937+ return self [ idx ]
938938 }
939939
940940 /// Returns a random element of the collection.
Original file line number Diff line number Diff line change @@ -445,16 +445,15 @@ extension MutableCollection where Self : RandomAccessCollection {
445445 public mutating func shuffle< T: RandomNumberGenerator > (
446446 using generator: inout T
447447 ) {
448- let count = self . count
449448 guard count > 1 else { return }
450449 var amount = count
451450 var currentIndex = startIndex
452451 while amount > 1 {
453- let random = generator . next ( upperBound : UInt ( amount) )
452+ let random = Int . random ( in : 0 ..< amount)
454453 amount -= 1
455454 swapAt (
456455 currentIndex,
457- index ( currentIndex, offsetBy: numericCast ( random) )
456+ index ( currentIndex, offsetBy: random)
458457 )
459458 formIndex ( after: & currentIndex)
460459 }
You can’t perform that action at this time.
0 commit comments