Probability round Float

This commit is contained in:
Olof Larsson 2016-02-28 21:05:45 +01:00
parent 54ab6bbfb2
commit d1aacefdec

View File

@ -1754,11 +1754,19 @@ public class MUtil
return d; return d;
} }
public static long probabilityRound(double val) public static long probabilityRound(double value)
{ {
long ret = (long) Math.floor(val); long ret = (long) Math.floor(value);
double prob = val % 1; double probability = value % 1;
if (MassiveCore.random.nextDouble() < prob) ret += 1; if (MassiveCore.random.nextDouble() < probability) ret += 1;
return ret;
}
public static int probabilityRound(float value)
{
int ret = (int) Math.floor(value);
float probability = value % 1;
if (MassiveCore.random.nextFloat() < probability) ret += 1;
return ret; return ret;
} }