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 trialPablo Alfaro
Courses Plus Student 6,923 PointsConfused about random number generated
I am little confused about the random number generated. The random number produces a large negative number and then it is converted into a smaller number within the bounds of the facts array. How is this number converted from large negative to a small positive number?
Here is the large negative number after pressing the 'show another fun fact' button
Here is the generated number after stepping into the next steps
1 Answer
Andrew Davis
6,367 PointsI believe arc4random_uniform() returns essentially a 32-bit pseudo-random number between -2,147,483,648 (-1 × 231) through 2,147,483,647 (231 - 1), then adjusts it to positive. But with the limit you've put on it (the self.facts.count), it is partitioning that number range by your limit, and giving you the order of the partition (in this case the 2nd).