create array of random numbers in swift

前端 未结 5 2077
面向向阳花
面向向阳花 2021-02-14 19:19

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

5条回答
  •  情书的邮戳
    2021-02-14 20:01

    Swift 5

    This creates an array of size 5, and whose elements range from 1 to 10 inclusive.

    let arr = (1...5).map( {_ in Int.random(in: 1...10)} )
    

提交回复
热议问题