21.07.2014, 17:59
Function name: generateRandomString
Use: Generates a random string according to length, and stores it at destination. Used commonly for reaction tests filtercsripts.
Code:
Test code:
Output from test code:
Additional Info: If you are planning to use it in reaction tests, remove char '%' and change validChars size to 76. (because in game % shows as #)
Use: Generates a random string according to length, and stores it at destination. Used commonly for reaction tests filtercsripts.
Code:
pawn Код:
static const
validChars[ 77 ] = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789!@#$%^&*()-_+=";
stock generateRandomString( dest[ ], len = 6 )
{
for ( new i = 0; i < len; ++ i )
dest[ i ] = validChars[ random( sizeof ( validChars ) - 1 ) ];
}
pawn Код:
#include < a_samp >
static const
validChars[ 77 ] = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789!@#$%^&*()-_+=";
stock generateRandomString( dest[ ], len = 6 )
{
for ( new i = 0; i < len; ++ i )
dest[ i ] = validChars[ random( sizeof ( validChars ) - 1 ) ];
}
public OnFilterScriptInit( )
{
new
str[ 20 ][ 12 ];
for ( new i; i < 20; ++ i )
{
generateRandomString( str[ i ], 12 );
print( str[ i ] );
}
return 1;
}
Код:
[01:25:11] %DqD2Q+I@SF$ [01:25:11] M(d1A9hE#&DC [01:25:11] DP8&wkH#=Goo [01:25:11] R4xMVp#ujhbx [01:25:11] _eZ+SD4L+VU6 [01:25:11] &xDMyG0vW53c [01:25:11] %b#fv3Mvo3rB [01:25:11] b&ITEfwX7tH* [01:25:11] 26NW$zy2n2_D [01:25:11] 86_T9347m8g- [01:25:11] z7YL37TFLNEq [01:25:11] gDi8d1!Zw-l! [01:25:11] *y4FoGu_Cz3u [01:25:11] EaRrvpS$&!l( [01:25:11] GMD#t_Y=#&^q [01:25:11] &_M$pTA-9Xnm [01:25:11] tvE_5Z7srHRG [01:25:11] XQ6Oz+w-2COD [01:25:11] #P+5n%Q=b03A [01:25:11] mY%=xk=CkdMw