20.11.2019, 16:33
Hi guy's I'm making a little system for my RP server for transfer "money" player to player like an IBAN code...then after taked a look on internet I didn't found nothing interesting, then I tryied a raw method, then it work.
It's various stock for get random strings, number, character.
This is a basic random method, hope you liked and it's usefull for who need it.
(sorry if I wrote wrong, I'm from Italy...then MAMMAMIA MARCELLO, pizzeria, mafia etc )
It's various stock for get random strings, number, character.
This is a basic random method, hope you liked and it's usefull for who need it.
(sorry if I wrote wrong, I'm from Italy...then MAMMAMIA MARCELLO, pizzeria, mafia etc )
how to use
for make it easy this is a little example:pawn Code:
CMD:test(playerid, params[])
{
new string[22];
format(string, sizeof(string), "%s", SizedRandomNumbers(10) );
SendClientMessage(playerid, -1, string);
return 1;
}
/*
the output will be a string with 10 random numbers
and not like using random(9999999999) where the output can be less than you wanted
*/
the code
pawn Code:
/* --- numbers --- */
stock SizedRandomNumbers(size)
{
new str[128];
for(new i=0; i<size; i++)
{
format(str, sizeof(str), "%s%d", str, random(9));
}
return str;
}
/* --- Characters --- */
stock SizedRandomUpperCharacters(size)
{
new str[128];
for(new i=0; i<size; i++)
{
new lettere = RandomEx(1, 26);
switch(lettere)
{
case 1: format(str, sizeof(str), "%sA", str);
case 2: format(str, sizeof(str), "%sB", str);
case 3: format(str, sizeof(str), "%sC", str);
case 4: format(str, sizeof(str), "%sD", str);
case 5: format(str, sizeof(str), "%sE", str);
case 6: format(str, sizeof(str), "%sF", str);
case 7: format(str, sizeof(str), "%sG", str);
case 8: format(str, sizeof(str), "%sH", str);
case 9: format(str, sizeof(str), "%sI", str);
case 10: format(str, sizeof(str), "%sL", str);
case 11: format(str, sizeof(str), "%sM", str);
case 12: format(str, sizeof(str), "%sN", str);
case 13: format(str, sizeof(str), "%sO", str);
case 14: format(str, sizeof(str), "%sP", str);
case 15: format(str, sizeof(str), "%sQ", str);
case 16: format(str, sizeof(str), "%sK", str);
case 17: format(str, sizeof(str), "%sJ", str);
case 18: format(str, sizeof(str), "%sR", str);
case 19: format(str, sizeof(str), "%sS", str);
case 20: format(str, sizeof(str), "%sT", str);
case 21: format(str, sizeof(str), "%sU", str);
case 22: format(str, sizeof(str), "%sV", str);
case 23: format(str, sizeof(str), "%sZ", str);
case 24: format(str, sizeof(str), "%sX", str);
case 25: format(str, sizeof(str), "%sY", str);
case 26: format(str, sizeof(str), "%sW", str);
}
}
return str;
}
stock SizedRandomDownCharacters(size)
{
new str[128];
for(new i=0; i<size; i++)
{
new lettere = RandomEx(1, 26);
switch(lettere)
{
case 1: format(str, sizeof(str), "%sa", str);
case 2: format(str, sizeof(str), "%sb", str);
case 3: format(str, sizeof(str), "%sc", str);
case 4: format(str, sizeof(str), "%sd", str);
case 5: format(str, sizeof(str), "%se", str);
case 6: format(str, sizeof(str), "%sf", str);
case 7: format(str, sizeof(str), "%sg", str);
case 8: format(str, sizeof(str), "%sh", str);
case 9: format(str, sizeof(str), "%si", str);
case 10: format(str, sizeof(str), "%sl", str);
case 11: format(str, sizeof(str), "%sm", str);
case 12: format(str, sizeof(str), "%sn", str);
case 13: format(str, sizeof(str), "%so", str);
case 14: format(str, sizeof(str), "%sp", str);
case 15: format(str, sizeof(str), "%sq", str);
case 16: format(str, sizeof(str), "%sk", str);
case 17: format(str, sizeof(str), "%sj", str);
case 18: format(str, sizeof(str), "%sr", str);
case 19: format(str, sizeof(str), "%ss", str);
case 20: format(str, sizeof(str), "%st", str);
case 21: format(str, sizeof(str), "%su", str);
case 22: format(str, sizeof(str), "%sv", str);
case 23: format(str, sizeof(str), "%sz", str);
case 24: format(str, sizeof(str), "%sx", str);
case 25: format(str, sizeof(str), "%sy", str);
case 26: format(str, sizeof(str), "%sw", str);
}
}
return str;
}
stock SizedRandomUDCharacters(size)
{
new str[128];
for(new i=0; i<size; i++)
{
new lettere = RandomEx(1, 52);
switch(lettere)
{
// lettere minuscole
case 1: format(str, sizeof(str), "%sa", str);
case 2: format(str, sizeof(str), "%sb", str);
case 3: format(str, sizeof(str), "%sc", str);
case 4: format(str, sizeof(str), "%sd", str);
case 5: format(str, sizeof(str), "%se", str);
case 6: format(str, sizeof(str), "%sf", str);
case 7: format(str, sizeof(str), "%sg", str);
case 8: format(str, sizeof(str), "%sh", str);
case 9: format(str, sizeof(str), "%si", str);
case 10: format(str, sizeof(str), "%sl", str);
case 11: format(str, sizeof(str), "%sm", str);
case 12: format(str, sizeof(str), "%sn", str);
case 13: format(str, sizeof(str), "%so", str);
case 14: format(str, sizeof(str), "%sp", str);
case 15: format(str, sizeof(str), "%sq", str);
case 16: format(str, sizeof(str), "%sk", str);
case 17: format(str, sizeof(str), "%sj", str);
case 18: format(str, sizeof(str), "%sr", str);
case 19: format(str, sizeof(str), "%ss", str);
case 20: format(str, sizeof(str), "%st", str);
case 21: format(str, sizeof(str), "%su", str);
case 22: format(str, sizeof(str), "%sv", str);
case 23: format(str, sizeof(str), "%sz", str);
case 24: format(str, sizeof(str), "%sx", str);
case 25: format(str, sizeof(str), "%sy", str);
case 26: format(str, sizeof(str), "%sw", str);
// Lettere maiuscole
case 27: format(str, sizeof(str), "%sA", str);
case 28: format(str, sizeof(str), "%sB", str);
case 29: format(str, sizeof(str), "%sC", str);
case 30: format(str, sizeof(str), "%sD", str);
case 31: format(str, sizeof(str), "%sE", str);
case 32: format(str, sizeof(str), "%sF", str);
case 33: format(str, sizeof(str), "%sG", str);
case 34: format(str, sizeof(str), "%sH", str);
case 35: format(str, sizeof(str), "%sI", str);
case 36: format(str, sizeof(str), "%sL", str);
case 37: format(str, sizeof(str), "%sM", str);
case 38: format(str, sizeof(str), "%sN", str);
case 39: format(str, sizeof(str), "%sO", str);
case 40: format(str, sizeof(str), "%sP", str);
case 41: format(str, sizeof(str), "%sQ", str);
case 42: format(str, sizeof(str), "%sK", str);
case 43: format(str, sizeof(str), "%sJ", str);
case 44: format(str, sizeof(str), "%sR", str);
case 45: format(str, sizeof(str), "%sS", str);
case 46: format(str, sizeof(str), "%sT", str);
case 47: format(str, sizeof(str), "%sU", str);
case 48: format(str, sizeof(str), "%sV", str);
case 49: format(str, sizeof(str), "%sZ", str);
case 50: format(str, sizeof(str), "%sX", str);
case 51: format(str, sizeof(str), "%sY", str);
case 52: format(str, sizeof(str), "%sW", str);
}
}
return str;
}