Last active
April 16, 2023 19:09
-
-
Save Morfly/06d9fad78a2e39b4aaeab68d7cb0111b to your computer and use it in GitHub Desktop.
Example of a 50/50 distribution for an A/B test based on randomly generated UUIDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
import kotlin.math.abs | |
fun main() { | |
var a = 0 | |
var b = 0 | |
for (i in 1..1000) { | |
val id = UUID.randomUUID().toString() | |
when (abs(id.hashCode() % 2)) { | |
0 -> a++ | |
1 -> b++ | |
else -> error("not reachable") | |
} | |
} | |
println("$a, $b") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment