From 5f29311813decfacced55ba6b019884620b7c199 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 26 Apr 2016 12:09:52 +0200 Subject: [PATCH] Fixing: - use Math.pow() ... - fixed formulars: wrong bait, wrong fish --- src/org/mxchange/jcustomercore/utils/CustomerUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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'); -- 2.39.5