If you want 0 to 2 ^ 32-1, you should use Random.nextLong() & 0xffffffffL instead of Random.nextInt() .
Java does not support unsigned types, which means that your int cannot take values ββin the range you need. To get around this, you use long , which has 64 bits and can take values ββin the required range.
source share