Added improved random number generator from SMLIB.
This commit is contained in:
parent
778ebc65f3
commit
3776eca312
@ -203,7 +203,7 @@ InfectOnClientDisconnect(client)
|
||||
}
|
||||
|
||||
// Get a random valid array index.
|
||||
new randindex = GetRandomInt(0, eligibleclients - 1);
|
||||
new randindex = Math_GetRandomInt(0, eligibleclients - 1);
|
||||
|
||||
// Get the client stored in the random array index.
|
||||
new randclient = GetArrayCell(arrayEligibleClients, randindex);
|
||||
|
@ -412,3 +412,27 @@ ZRBoolToString(bool:value, String:output[], maxlen)
|
||||
strcopy(output, maxlen, "0");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* (from SMLIB 0.10.2)
|
||||
*
|
||||
* Returns a random, uniform Integer number in the specified (inclusive) range.
|
||||
* This is safe to use multiple times in a function.
|
||||
* The seed is set automatically for each plugin.
|
||||
* Rewritten by MatthiasVance, thanks.
|
||||
*
|
||||
* @param min Min value used as lower border
|
||||
* @param max Max value used as upper border
|
||||
* @return Random Integer number between min and max
|
||||
*/
|
||||
#define SIZE_OF_INT 2147483647 // without 0
|
||||
stock Math_GetRandomInt(min, max)
|
||||
{
|
||||
new random = GetURandomInt();
|
||||
|
||||
if (random == 0) {
|
||||
random++;
|
||||
}
|
||||
|
||||
return RoundToCeil(float(random) / (float(SIZE_OF_INT) / float(max - min + 1))) + min - 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user