This is a slightly annoying thing to have to write, it would be nice to have a Random.nextInt(min,max) inclusive.
private static final int MAX_KEY_SIZE = 120;
private static final int MIN_KEY_SIZE = 1;
...
// Assumes MAX_KEY_SIZE >> MIN_KEY_SIZE
int keyLen = generator.nextInt(MAX_KEY_SIZE - MIN_KEY_SIZE + 1) +
MIN_KEY_SIZE;
Other possibilities include a Math.random(int) that can be used
without worrying about creating your own Random if you don't care about it,
and perhaps a Random.nextLong(long).
###@###.### 2004-06-03
private static final int MAX_KEY_SIZE = 120;
private static final int MIN_KEY_SIZE = 1;
...
// Assumes MAX_KEY_SIZE >> MIN_KEY_SIZE
int keyLen = generator.nextInt(MAX_KEY_SIZE - MIN_KEY_SIZE + 1) +
MIN_KEY_SIZE;
Other possibilities include a Math.random(int) that can be used
without worrying about creating your own Random if you don't care about it,
and perhaps a Random.nextLong(long).
###@###.### 2004-06-03
- duplicates
-
JDK-6336049 (rand) Better pseudo random number generators
- Open