4242final class ConditionEvaluator {
4343 private static final int MAX_CONDITION_RECURSION_DEPTH = 10 ;
4444 private static final Logger logger = LoggerFactory .getLogger (ConditionEvaluator .class );
45+ private static final BigInteger MICRO_PERCENT_MODULO = BigInteger .valueOf (100_000_000L );
4546
4647 /**
4748 * Evaluates server conditions and assigns a boolean value to each condition.
@@ -226,8 +227,7 @@ private BigInteger getMicroPercentile(String seed, String randomizationId) {
226227 String seedPrefix = seed != null && !seed .isEmpty () ? seed + "." : "" ;
227228 String stringToHash = seedPrefix + randomizationId ;
228229 BigInteger hash = hashSeededRandomizationId (stringToHash );
229- BigInteger modValue = new BigInteger (Integer .toString (100 * 1_000_000 ));
230- BigInteger microPercentile = hash .mod (modValue );
230+ BigInteger microPercentile = hash .mod (MICRO_PERCENT_MODULO );
231231
232232 return microPercentile ;
233233 }
@@ -238,19 +238,8 @@ private BigInteger hashSeededRandomizationId(String seededRandomizationId) {
238238 MessageDigest digest = MessageDigest .getInstance ("SHA-256" );
239239 byte [] hashBytes = digest .digest (seededRandomizationId .getBytes (StandardCharsets .UTF_8 ));
240240
241- // Convert the hash bytes to a hexadecimal string.
242- StringBuilder hexString = new StringBuilder ();
243- for (byte b : hashBytes ) {
244- String hex = Integer .toHexString (0xff & b );
245- if (hex .length () == 1 ) {
246- hexString .append ('0' );
247- }
248- hexString .append (hex );
249- }
250-
251- // Convert the hexadecimal string to a BigInteger
252- return new BigInteger (hexString .toString (), 16 );
253-
241+ // Convert the hash bytes to a BigInteger
242+ return new BigInteger (1 , hashBytes );
254243 } catch (NoSuchAlgorithmException e ) {
255244 logger .error ("SHA-256 algorithm not found" , e );
256245 throw new RuntimeException ("SHA-256 algorithm not found" , e );
0 commit comments