Skip to content

Commit 1e311e9

Browse files
committed
multiply before converting to ulong
1 parent 80652aa commit 1e311e9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/kotlin/com/statsig/sdk/Evaluator.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ internal class Evaluator(
236236
'.' +
237237
(getUnitID(user, rule.idType) ?: "")
238238
)
239-
.mod(10000f) < rule.passPercentage.times(100f)
239+
.mod(10000UL) < (rule.passPercentage.times(100.0)).toULong()
240240

241241
return ConfigEvaluation(
242242
false,
@@ -378,7 +378,7 @@ internal class Evaluator(
378378
ConfigCondition.USER_BUCKET -> {
379379
val salt = getValueAsString(condition.additionalValues["salt"])
380380
val unitID = getUnitID(user, condition.idType) ?: ""
381-
value = computeUserHash("$salt.$unitID").mod(1000f)
381+
value = computeUserHash("$salt.$unitID").mod(1000UL)
382382
}
383383
ConfigCondition.UNIT_ID -> {
384384
value = getUnitID(user, condition.idType)
@@ -867,11 +867,11 @@ internal class Evaluator(
867867
?: user.statsigEnvironment?.get(field.lowercase())
868868
}
869869

870-
private fun computeUserHash(input: String): Float {
870+
private fun computeUserHash(input: String): ULong {
871871
val md = MessageDigest.getInstance("SHA-256")
872872
val inputBytes = input.toByteArray()
873873
val bytes = md.digest(inputBytes)
874-
return ByteBuffer.wrap(bytes).float
874+
return ByteBuffer.wrap(bytes).long.toULong()
875875
}
876876

877877
private fun getUnitID(user: StatsigUser, idType: String?): String? {

0 commit comments

Comments
 (0)