Effective Java Item 47: Know and use your libraries - Flawed random integer method example
问题 In the example Josh gives of the flawed random method that generates a positive random number with a given upper bound n , I don't understand the two of the flaws he states. The method from the book is: private static final Random rnd = new Random(); //Common but deeply flawed static int random(int n) { return Math.abs(rnd.nextInt()) % n; } He says that if n is a small power of 2, the sequence of random numbers that are generated will repeat itself after a short period of time. Why is this