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!
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
Arcee Palabrica8,100 Points
Code variations which one is more advisable to use...
I was just curious and tried using different code variations to generate 3 random numbers. How is it different from the one used in this video and which one is advisable to use?
Generating Random Numbers:
int randomNumber = (int) (Math.random() * 3); // versus int randomNumber = randomGenerator.nextInt(3);
Assign randomNumber to fact:
fact = Integer.toString(randomNumber); //versus fact = randomNumber + "";
I still got the same result when I ran the app.
Ben DeitchTreehouse Teacher
Hey Arcee! There's not always a clear best way to do something. Each of those code variations should work just fine; feel free to pick your favorite :)