[Pedido] Lуgica sobre random utilizando letras e nъmeros
#1

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.
Reply
#2

Nгo entendi.
Reply
#3

Vou tentar simplificar.

Uma funзгo, que crie valores aleatуrios usando caracteres de 0 a 9 e A - Z.
Reply
#4

Tenta utilizar random.
Reply
#5

Vocк pode utilizar a tabela ASCII + random para poder fazer isto, exemplo.

PHP код:
stock Randomizar() {
    new 
letters;
    
letters random(25) + 97;
    
printf("%c%d%c%d%c%d"letters 1random(100 >> 2), letters -2random(1000 >> 4) , letters -3random(80 >> 1));
    return 
true;

Reply
#6

Quote:
Originally Posted by Adejair_Junior
Посмотреть сообщение
Vocк pode utilizar a tabela ASCII + random para poder fazer isto, exemplo.

PHP код:
stock Randomizar() {
    new 
letters;
    
letters random(25) + 97;
    
printf("%c%d%c%d%c%d"letters 1random(100 >> 2), letters -2random(1000 >> 4) , letters -3random(80 >> 1));
    return 
true;

Tб tendo um probleminha, ela estб me retornando outros tipos de caracteres. Eu sу quero que as mesmas retornem letras e nъmeros. OBS: Estou usando o PAWNO como compilador.
Reply
#7

Veja a lуgica do alfabeto com elipse que o ipsBruno fez neste tуpico:

https://sampforum.blast.hk/showthread.php?tid=365996

Utilizando facilmente da para fazer com letras maiъsculas, minusculas e nъmeros.
Reply
#8

Код:
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;
}
OBS: Nгo testei
Reply
#9

Faz tempo que nгo programo, mas uma lуgica boa para se fazer й algo mais ou menos assim


PHP код:

stock alfabeto 
+ ('z' 'a') ] = { 'a''b', ...}  ;
stock numeros + ('9' '0') ] = { '0''1', ...}  ;
stock GetRandomString(size 0xff)
{
    static 
stringBuff[0xff];
    if(
size 0xff && size) {
        for(new 
i!= sizei++) stringBuff[i] = boolrandom(2) ? numeros [random(sizeof numeros )] : alfabeto [random(sizeof alfabeto )];
        
stringBuff[size] = EOS;
    }
    return 
stringBuff;

Dai tu faz:

PHP код:
print(GetRandomString(5)); 
e irб gerar um texto aleatуrio de 5 caracteres


Saida:

Код:
[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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)