create array of random numbers in swift
问题 I'm just starting to learn swift. I'm attempting to create an array of several random numbers, and eventually sort the array. I'm able to create an array of one random number, but what's the best way to iterate this to create an array of several random numbers? func makeList() { var randomNums = arc4random_uniform(20) + 1 let numList = Array(arrayLiteral: randomNums) } makeList() Any help is greatly appreciated. 回答1: Edit/update: Swift 4.2 or later In Swift 4.2 there is a new static method