Here's the simple method that gave me the error:
protected static long random(long a, long b) {
//Random random = new Random();
return a + new Random().nextLong(b - a);
}
And here are the errors from the terminal:
java: method nextLong in class java.util.Random cannot be applied to given types;
required: no arguments
found: long
reason: actual and formal argument lists differ in length
Using
ThreadLocalRandom, there's no need for your helper method:This is available in Java 7 and later. Earlier on,
Randomdid not have some of the helper methods provided throughRandomGenerator(in Java 17), so you only have theRandom#nextLong()method (with no arguments). This number had to be manually modulo'd, which can lead to distribution issues down the line. It's much better to useThreadLocalRandomhere in this case, as it will be uniformly distributed.