Reading random values from an array

前端 未结 5 1275
长情又很酷
长情又很酷 2021-01-18 11:39

I have an array with a 14 strings. I want to display each of these 14 strings to the user without duplicates. The closest I got was creating an array of integers and shuffli

5条回答
  •  死守一世寂寞
    2021-01-18 12:09

    Get the elements in your array like this:

    int position = arc4random() % ([myArray count]);
    

    This way even though count decreases by one, that is ok, as you will still get a valid next position value till there aren't any more posible values.

提交回复
热议问题