While FRand() may equalize to 1.0, it should have always a 1/32768 chance in this case (that's around 0.0031%), considering what Higor said about FRand, so just decrementing the integer multiplication by 1 is only going to make the last element to have this much of a change to actually be selected over time, while the rest will have a much higher chance to appear.
In other words, if you have 3 elements, and you are counting with FRand() equalizing to 1.0, then the chance of each one is not 33%, but rather the chance of the 2 first elements will be almost 50% each (around 49.995% specifically), while the last one will only appear in 0.0031% of the times.
If you are working with integers, especially to select elements from an array, you're better off with Rand which does exclude the Max value as a possible value, so you don't have to worry about this.
If you however absolutely need a floating point random generator, and you need to exclude the 1.0 from one of the possible outcomes, you can just create your own random function:
Code: Select all
static function float frandom()
{
local float f;
f = frand();
if (f == 1.0) {
f = 0.0;
}
return f;
}
In other words, whenever it's 1.0, return 0.0 instead. This will effectively make 0.0 being the number with double the chances of appearing, but that's just 2 in 32768, or 0.0061%, so it's negligible in my opinion.
Another more fair way would be:
Code: Select all
static function float frandom()
{
return float(rand(16777216)) / 16777216.0;
}
By taking advantage of the fact that Rand excludes the Max as being a possible value, although if it didn't, since we're working with integers here, it would be trivial to just use 16777215 instead inside Rand.
But this would be just a slightly slower way of doing, processing wise, but it's also a negligible difference.
Also,16777216 is a number which represents the maximum integer number a 32 bits float can represent without loosing precision.