Say I have an array with objects, 1, 2, 3 and 4.
How would I pick a random object from this array?
Say I have an array with objects, 1, 2, 3 and 4. How would
Share
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.
@Darryl’s answer is correct, but could use some minor tweaks:
Modifications:
arc4random()overrand()andrandom()is simpler because it does not require seeding (callingsrand()orsrandom()).%) makes the overall statement shorter, while also making it semantically clearer.