Need help understanding random class in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need help understanding random class in java

So I am currently trying to get hold off the random class and how its range works. Lets say that i have "Random rand = new Random(); and i want to figure out rand.nextInt(10) * 4; I get how to work with its range when using addition and subtraction (+, -) but I cant work around the multiplication and division. Can someone please explain it.

22nd Sep 2019, 4:10 PM
William Omø
William Omø - avatar
1 Answer
+ 6
rand.nextInt(10) returns a random integer from 0 to 9... now you are multiplying that number by 4. min number is 0*4=0 max number is 9*4= 36 So you will get a number in range [0,36] All possible outputs: 0,4,8,16,20,24,28,32,36
22nd Sep 2019, 4:26 PM
voja
voja - avatar