]> git.mxchange.org Git - jcustomer-core.git/commitdiff
Fixing:
authorRoland Häder <roland@mxchange.org>
Tue, 26 Apr 2016 10:09:52 +0000 (12:09 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 26 Apr 2016 10:16:45 +0000 (12:16 +0200)
- use Math.pow() ...
- fixed formulars: wrong bait, wrong fish

src/org/mxchange/jcustomercore/utils/CustomerUtils.java

index be29c8dc8176f342ed645ddd331c90c3e3994547..1681d8a5d49f5f879a5951832d22d76e0a98ba56 100644 (file)
@@ -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');