Get random string - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get random string (
/showthread.php?tid=636414)
Get random string -
HoussemGaming - 26.06.2017
Hey all.
I use random(max) to get a random number
is there any way to get a random string ?
Re: Get random string -
Logic_ - 26.06.2017
I dont remember properly but you can do it using ASCII <something> and using random.
Re: Get random string -
Vince - 26.06.2017
PHP код:
stock minrandom(min, max)
return min + random(max - min);
PHP код:
new randomString[10];
for(new i; i < sizeof randomString; i++)
{
randomString[i] = minrandom('A', 'Z');
}
If you also want lowercase letters and numbers then you can use another call to random to randomize that, too.
Re: Get random string -
SyS - 27.06.2017
pawn Код:
GenString( string[ ] , size = sizeof string )
{
static const Data[ ] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//add more characters if they want to include in string
new i;
for(i = 0 ; i < size; ++i)
string[ i ] = Data[ random( sizeof Data ) ];
}
pawn Код:
new string[10];
GenString(string);
printf("random string : %s ",string);
Re: Get random string -
OuDayas - 20.03.2019
Quote:
Originally Posted by SyS
pawn Код:
GenString( string[ ] , size = sizeof string ) { static const Data[ ] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//add more characters if they want to include in string new i; for(i = 0 ; i < size; ++i) string[ i ] = Data[ random( sizeof Data ) ]; }
pawn Код:
new string[10]; GenString(string); printf("random string : %s ",string);
|
I tryied this code like this...but pawno give me 2 warning, who told me about the functions that should have a return value, how I fix that?
pawn Код:
CMD:provahash(playerid, params[])
{
new str[256];
new strfull[10], strnf[10];
format(str, sizeof(str), "{FFFFFF}Full: {FFFF00}%s", RandomStringFull(strfull));
SendClientMessage(playerid, -1, str);
format(str, sizeof(str), "{FFFFFF}no full: {FFFF00}%s", RandomString(strnf));
SendClientMessage(playerid, -1, str);
format(str, sizeof(str), "{FFFFFF}numbers: {FFFF00}%d", random(999999999));
SendClientMessage(playerid, -1, str);
return 1;
}
RandomString( string[ ] , size = sizeof string )
{
static const Data[ ] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//add more characters if they want to include in string
new i;
for(i = 0 ; i < size; ++i)
string[ i ] = Data[ random( sizeof Data ) ];
}
RandomStringFull( string[ ] , size = sizeof string )
{
static const Data[ ] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!Ј$%&/()=?'^мий+*тза°щ§,;.:-_<>";//add more characters if they want to include in string
new i;
for(i = 0 ; i < size; ++i)
string[ i ] = Data[ random( sizeof Data ) ];
}
Re: Get random string -
NaS - 20.03.2019
Quote:
Originally Posted by OuDayas
I tryied this code like this...but pawno give me 2 warning, who told me about the functions that should have a return value, how I fix that?
pawn Код:
CMD:provahash(playerid, params[]) { new str[256]; new strfull[10], strnf[10]; format(str, sizeof(str), "{FFFFFF}Full: {FFFF00}%s", RandomStringFull(strfull)); SendClientMessage(playerid, -1, str); format(str, sizeof(str), "{FFFFFF}no full: {FFFF00}%s", RandomString(strnf)); SendClientMessage(playerid, -1, str); format(str, sizeof(str), "{FFFFFF}numbers: {FFFF00}%d", random(999999999)); SendClientMessage(playerid, -1, str); return 1; }
RandomString( string[ ] , size = sizeof string ) { static const Data[ ] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//add more characters if they want to include in string new i; for(i = 0 ; i < size; ++i) string[ i ] = Data[ random( sizeof Data ) ]; }
RandomStringFull( string[ ] , size = sizeof string ) { static const Data[ ] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!Ј$%&/()=?'^мий+*тза°щ§,;.:-_<>";//add more characters if they want to include in string new i; for(i = 0 ; i < size; ++i) string[ i ] = Data[ random( sizeof Data ) ]; }
|
Those functions do not return anything, but you put them into the format line. That's why the compiler complains.
You should move the functions out of the format call, since they modify the arguments that get passed to them (by reference).
Use them like this:
Код:
new string[50];
RandomString(string); // string will now contain the random string
Re: Get random string -
B3x7K - 20.03.2019
Use RyDeR function:
https://forum.sa-mp.com/showpost.php...55&postcount=5