Skip to content

Instantly share code, notes, and snippets.

@Morfly
Last active April 16, 2023 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Morfly/06d9fad78a2e39b4aaeab68d7cb0111b to your computer and use it in GitHub Desktop.
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
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