-
-
Save artjomb/9320b8c91e30b78e3706408e023d61a1 to your computer and use it in GitHub Desktop.
calculating the birthday probability for 100000 in 2^170
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.math.*; | |
BigDecimal r = new BigDecimal(2); | |
r = r.pow(160); | |
MathContext c = new MathContext(1000); | |
BigDecimal result = new BigDecimal(1); | |
for(int i = 0; i < 100000; i++) { | |
result = result.multiply(r.subtract(new BigDecimal(i)).divide(r)).round(c); | |
} | |
println BigDecimal.ONE.subtract(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment