StringBuilder customerNumber = new StringBuilder(totalLength);
// Calculate total blockas
- long totalBlocks = Math.round(totalLength / (blockSize - 1) - 0.5);
+ long totalBlocks = Math.round(totalLength / (blockSize - 1) - 0.5) - 1;
// Generate CN
for (int i = 0; i < totalBlocks; i++) {
}
// Calculate remaining charcters
- long remain = totalLength - blockSize * totalBlocks;
+ long remain = totalLength - (blockSize + 1) * totalBlocks;
// Generate new block and append it
customerNumber.append(genrateBlock((short) remain));
*/
private static String genrateBlock (final short blockSize) {
// Generate random number
- int num = RANDOM_NUMBER_GENERATOR.nextInt(10 ^ blockSize);
+ int num = RANDOM_NUMBER_GENERATOR.nextInt((int) Math.pow(10, blockSize));
// Generate "block" and return it
return StringUtils.leftPad(String.valueOf(num), blockSize, '0');