From 3f0daeded7c78ee11aa9b5e1fa7a4d2f7cce433b Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 21 Dec 2015 00:04:51 -0800 Subject: [PATCH] Index.Distance has to be IntMax --- Sources/CollectionType.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/CollectionType.swift b/Sources/CollectionType.swift index 02b6b2d..87c0fbf 100644 --- a/Sources/CollectionType.swift +++ b/Sources/CollectionType.swift @@ -49,9 +49,9 @@ public extension CollectionType where Index: RandomAccessIndexType { guard !isEmpty else { return nil } - let max = Int(count.toIntMax()) - let n = randomInt(max) - 1 - return self[startIndex.advancedBy(n)] + let n = Int(count.toIntMax()) + let i = startIndex.advancedBy(Index.Distance(IntMax(randomInt(n) - 1))) + return self[i] } }