12.04.2012, 14:34
(
Последний раз редактировалось RyDeR`; 13.04.2012 в 00:51.
)
This is another possibility by me (used in my FloodControl.inc):
Not sure about the performance, but I guess it's slightly faster and if not, the same.
EDIT:
Small function that randomly shuffles a string. For example:
pawn Код:
stock IpToInt(const szIP[]) {
new
aiBytes[1],
iPos = 0
;
aiBytes{0} = strval(szIP[iPos]);
while(szIP[iPos] != EOS && szIP[iPos++] != '.') {}
aiBytes{1} = strval(szIP[iPos]);
while(szIP[iPos] != EOS && szIP[iPos++] != '.') {}
aiBytes{2} = strval(szIP[iPos]);
while(szIP[iPos] != EOS && szIP[iPos++] != '.') {}
aiBytes{3} = strval(szIP[iPos]);
return aiBytes[0];
}
EDIT:
pawn Код:
stock shuffleString(szStr[]) {
for(new i = 0, iLen = strlen(szStr), iRand = 0, iTemp = 0; i < iLen; ++i) {
iRand = i + (random(0) % (iLen - i));
iTemp = szStr[i], szStr[i] = szStr[iRand], szStr[iRand] = iTemp;
}
}
pawn Код:
new
szStr[] = "RyDeR`"
;
shuffleString(szStr);
printf("%s", szStr); // Possible output: "yReR`D"