This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

Hi, As per the API random function "Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range." That means you will get something between 0 and 1(non-inclusive) like 0.1, 0.2,.03 .... 0.999. Any number within this range when multiplied by 4 wil give values between 0 to 4 like .1*4 = .4 , .6*4 = 2.4 ..... .999*4 = 3.996.

And I forgot to mention that when these numbers will be casted to (int) the values after decimal will be lost .1*4 = .4 which becomes 0, .6*4 = 2.4 which becomes 2..... .999*4 = 3.996 which becomes 3