24.02.2015, 15:17
Olб a todos. Estou querendo saber uma metodologia que faзa com que eu crie valores randфmicos utilizando letras nъmeros e utilizando pelo menos 6 caracterнsticas. Somente isso, quero apenas uma lуgica.
stock Randomizar() {
new letters;
letters = random(25) + 97;
printf("%c%d%c%d%c%d", letters - 1, random(100 >> 2), letters -2, random(1000 >> 4) , letters -3, random(80 >> 1));
return true;
}
Vocк pode utilizar a tabela ASCII + random para poder fazer isto, exemplo.
PHP код:
|
new letters[27][1] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; stock GenerateRandomSerial(string[]) { for(new c; c < sizeof(string), c++) { new type = random(2); switch(type) { case 0: format(string, sizeof(string), "%d", random(10)); case 1: string[c] = letters[random(27)]; } } return string; }
stock alfabeto [ 1 + ('z' - 'a') ] = { 'a', 'b', ...} ;
stock numeros [ 1 + ('9' - '0') ] = { '0', '1', ...} ;
stock GetRandomString(size = 0xff)
{
static stringBuff[0xff];
if(size < 0xff && size) {
for(new i; i != size; i++) stringBuff[i] = bool: random(2) ? numeros [random(sizeof numeros )] : alfabeto [random(sizeof alfabeto )];
stringBuff[size] = EOS;
}
return stringBuff;
}
print(GetRandomString(5));
[15:08:53] 7m639 [15:08:53] 66uml [15:08:53] 9ujrm [15:08:53] h8v90 [15:08:53] zgkqq [15:08:53] 1ky92 [15:08:53] 5q14o