January 2014
Intermediate to advanced
736 pages
70h 43m
English
The preceding statement always assigns to variable face an integer in the range 1 ≤face ≤6. The width of this range (i.e., the number of consecutive integers in the range) is 6, and the starting number in the range is 1. The width of the range is determined by the number 6 that’s passed as an argument to Random method nextInt, and the starting number of the range is the number 1 that’s added to the result of calling nextInt. We can generalize this result as
number = shiftingValue + randomNumbers.nextInt( scalingFactor );
where shiftingValue specifies the first number in the desired range of consecutive integers and scalingFactor specifies how many numbers are in the range. ...
Read now
Unlock full access