https://travelbeeee.tistory.com/4
let randomInt = 123
var randomArr = Array<Int>(repeating: 0, count: 3)
for i in 0...2 {
let currentDigit: Double = Double(3 - i)
let randomNum = (randomInt % Int(pow(10.0, currentDigit))) / Int(pow(10.0, currentDigit - 1))
randomArr[i] = randomNum
}
// randomArr = [1, 2, 3]
숫자가 321 이면
3 = (321 % 1000) / 100
2 = (321 % 100) / 10
1 = (321 % 10)
참고로 숫자 전체의 자리수를 구하려면 String(숫자).count
가 가장 간단한 방법이다.