Skip to content

Instantly share code, notes, and snippets.

@Morfly
Last active April 16, 2023 19:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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