I’ve NSArray with over 100 strings.
I would like to pick 4 different strings randomly. I can write traditional way of code using for/while loops and get the task done.
But is there any better way to pick 4 different random strings?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I wrote some utils as category on NSArray.
You could use it like this:
This will give you a set of 4 unique random elements.
If you want to allow objects to be in your collection more than once you can do: