新手自学java遇到的小疑点(3),求高手解答

新手自学java遇到的小问题(3),求高手解答。
以下是《Core Java》中的示例代码: 

1. import java.util.*;
 2.
 3. public class LotteryDrawing
 4. {
 5. public static void main(String[] args)
 6. {
 7. Scanner in = new Scanner(System.in);
 8.
 9. System.out.print("How many numbers do you need to draw? ");
10. int k = in.nextInt();
11.
12. System.out.print("What is the highest number you can draw? ");
13. int n = in.nextInt();
14.
15. // fill an array with numbers 1 2 3 . . . n
16. int[] numbers = new int[n];
17. for (int i = 0; i < numbers.length; i++)
18. numbers[i] = i + 1;
19.
20. // draw k numbers and put them into a second array
21. int[] result = new int[k];
22. for (int i = 0; i < result.length; i++)
23. {
24. // make a random index between 0 and n - 1
25. int r = (int) (Math.random() * n);
26.
27. // pick the element at the random location
28. result[i] = numbers[r];
29.
30. // move the last element into the random location
31. numbers[r] = numbers[n - 1];
32. n--;
33. }
34.
35. // print the sorted array
36. Arrays.sort(result);
37. System.out.println("Bet the following combination. It'll make you rich!");
38. for (int r : result)
39. System.out.println(r);
40. }
41. }

我貌似发现这段代码中的一个小错误,第25行的“n”是否应该换成“(n-1)”
因为我认为如果这里是“n”的话如果生成的随机数是“1”的话“r”就会等于“n”了
而当后面的28和31行中的代码中使用“r”作为数组下标时就会发生指向错误了。

我的想法不知道是否正确,不敢贸然挑战权威,请高人指点。

------解决方案--------------------
不需要,循环里有:
Java code
n --

------解决方案--------------------
Returns a <code>double</code> value with a positive sign, greater than or equal to <code>0.0</code> and less than <code>1.0</code>. 


Math.random()不会返回1