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 {
929
929
using generator: inout T
930
930
) -> Element ? {
931
931
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 (
934
934
startIndex,
935
- offsetBy: numericCast ( random)
935
+ offsetBy: random
936
936
)
937
- return self [ index ]
937
+ return self [ idx ]
938
938
}
939
939
940
940
/// 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 {
445
445
public mutating func shuffle< T: RandomNumberGenerator > (
446
446
using generator: inout T
447
447
) {
448
- let count = self . count
449
448
guard count > 1 else { return }
450
449
var amount = count
451
450
var currentIndex = startIndex
452
451
while amount > 1 {
453
- let random = generator . next ( upperBound : UInt ( amount) )
452
+ let random = Int . random ( in : 0 ..< amount)
454
453
amount -= 1
455
454
swapAt (
456
455
currentIndex,
457
- index ( currentIndex, offsetBy: numericCast ( random) )
456
+ index ( currentIndex, offsetBy: random)
458
457
)
459
458
formIndex ( after: & currentIndex)
460
459
}
You can’t perform that action at this time.
0 commit comments