From: Roland Häder Date: Tue, 26 Apr 2016 10:09:52 +0000 (+0200) Subject: Fixing: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5f29311813decfacced55ba6b019884620b7c199;p=jcustomer-core.git Fixing: - use Math.pow() ... - fixed formulars: wrong bait, wrong fish --- diff --git a/src/org/mxchange/jcustomercore/utils/CustomerUtils.java b/src/org/mxchange/jcustomercore/utils/CustomerUtils.java index be29c8d..1681d8a 100644 --- a/src/org/mxchange/jcustomercore/utils/CustomerUtils.java +++ b/src/org/mxchange/jcustomercore/utils/CustomerUtils.java @@ -64,7 +64,7 @@ public class CustomerUtils { 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++) { @@ -73,7 +73,7 @@ public class CustomerUtils { } // 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)); @@ -92,7 +92,7 @@ public class CustomerUtils { */ 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');