- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
private String get4DigitRandom() {
final int length = 4;
int number = (int) (Math.random() * Math.pow(10, length));
StringBuilder sb = new StringBuilder();
for (int i = length; i > 0; i--)
sb.append("" + (int) (number / Math.pow(10, i - 1)) % 10);
return sb.toString();
}