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 trialWuen Han Lee
Courses Plus Student 2,305 PointsMath.floor(Math.random() * 256 We wont be getting 256 with this line, will we?
since 1 is exclusive from Math.random(). Are we eliminating the possibility of getting 256?
2 Answers
Derek Gibson
6,531 PointsYou ARE correct in thinking that getting a value of 256 is impossible, but... the reason for omitting the 256th value is that we only want a value of 0-255 because that is the acceptable range for RGB numbers.
Brian Hankins
5,735 PointsShort answer = No.
Reason: A random number generator always returns a value between 0 and 1, but never equal to one or the other. So the random number will be from 0.000000001 - 0.999999999. (Okay, really it could return a 0.00000000 but its highly, nearly impossible). So, with Math.floor(Math.random() * 256, you're going to return a random value from 0 to 255.
Wuen Han Lee
Courses Plus Student 2,305 PointsIn this refactor challenge, dave use this line without +1. Im wondering if there any reason for omitting the 256th value?