Why does this code using random strings print “hello world”? The following print statement would print "hello world". Could anyone explain this? System.out.println(randomString(-229985452) + " " + randomString(-147909649)); And randomString() looks like this: public static String randomString(int i) { Random ran = new Random(i); StringBuilder sb = new StringBuilder(); while (true) { int k = ran.nextInt(27); if (k == 0) break; sb.append((char)('`' + k)); } return sb.toString(); } answer: When an instance of java.util.Random is constructed with a specific seed parameter (in this case -229985452 or -147909649), it follows the
undefined
How to generate random integers within a specific range in Java? I am trying to generate a random intvalue with Java, but in a specific range. For example: My range is 5-10, meaning that 5 is the smallest possible value and 10 is the biggest. Any other number in between these numbers is possible to be a value, too. In Java, there is a method random() in the Math class, which returns a double value between 0.0 and 1.0. In the class Random there is the method nextInt(int n), which returns a random intvalue in the range of 0 (inclusive) and n (exclusive). I couldn't find