You actually need a random value that have a chance of happening as the hero crit chance, for instance if a hero has 17% percent crit chance and you have a random function that gives you one of one hundred values then 17 of those values (selected in any manner) should actually make a crit hit happen (that is if all one hundred values have the same chance of happening) to translate this to code:
We'll use Random.nextInt(99);
this should give us one of one hundred (almost evenly distributed) values. If hero crit chance is expressed as an integer between 0 and 100 (eg 17) now the probability that the returned value by nextInt is a number between 0 - 16 is actually 17% so we can express that in code like this:
rand = Random.nextInt(99);
if(rand <= critchance - 1){
//we have a crit
}