crit chance in java

Java
int percentage = ((int)(Math.random() * 100));
Source

Also in Java: