Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Enhancing a Quiz App in iOS

1 Answer

Ben Shockley
Ben Shockley
6,094 Points

I am currently working on an app that is doing this.

So as each random number is generated I append it to an array called previouslyUsedNumbers. Then in my generateRandomNumber function there is a loop that generates a new random number, then checks the previouslyUsedNumbers array to see if it has been used before. If it has, it goes back and generates another random number and rechecks, etc. If that number hasn't been used before it returns that number, and appends it to the array.

Hope this helps?