랜덤값을 중복되지 않게 추출

2017. 9. 12. 16:54Programming/Swift

반응형

import UIKit


var totalCount = 18

var gemCard = 1

var ranArray = [1,2,3,4,5,6,7,8,9,10,11,12,13]


while(totalCount>0) {

    

    let randomIndex = Int(arc4random_uniform(UInt32(ranArray.count)))

    print(ranArray[randomIndex])

    

    ranArray.remove(at: randomIndex)

    

    totalCount-=2

} 


반응형