Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

What is something important that you learned in class last Friday?

+3 votes
I had to miss class on Friday, October 6th for a golf tournament, so I was just wondering what stuck out as something important to know!?
asked Oct 9, 2017 in CSC 211 (F17) by Jillian Stone (100 points)

1 Answer

+2 votes
We learned about the Random object! It can be useful to generate random numbers in java, so you construct a random object by typing Random <variable> = new Random(); and in the parentheses, put the range of numbers you want the Random object to choose from. For example, if you put Random r = new Random(5); that would pick a random number between 0 and 4 because it will choose an integer up to but not including 5. If you wanted to include 5 in that set of numbers, you would put 6 in the parentheses. However, if you just wanted a random number between 1 and 5 instead of 0 and 5, you could write Random r = new Random(5) + 1, because it will generate a random number between 0 and 4 and then add 1, giving you a random number between 1 and 5.
answered Oct 9, 2017 by Lauren Endress (100 points)