Random Plate?
#1

pawn Код:
random(26) + 'A'
Would that produce the random letters that I want and then how would I be able to make random numbers and then mix the two together to make a plate like this: L3S - E9R7
Reply
#2

Is this good for you, or you want a very random plate mixed by numbers and letters?
Код:
new plate[8];
plate[0] = 65 + random(26);
plate[1] = random(10);
plate[2] = 65 + random(26);
plate[3] = '-';
plate[4] = 65 + random(26);
plate[5] = random(10);
plate[6] = 65 + random(26);
plate[7] = random(10);
Reply
#3

pawn Код:
#define MAX_VEHICLE_PLATE 8
new string[MAX_VEHICLE_PLATE];
new const charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

for(new i; i < MAX_VEHICLE_PLATE; i++)
{
if(i == 3)string[i] = '-';
else string[i] = charset[RandomEx(0, sizeof(charset) - 1)];
}

RandomEx(min, max)return random(max - min) + min;
Reply
#4

California's license plate template goes as follows: 1ABC234
I'm explaining California's plates because Los Santos mimicks Los Angeles, California
Reply
#5

So will they be random as in it will make random letters and number mixed together?
Reply
#6

Код:
const len = 7, hyphenpos = 4;
  new plate[len+1];
  for (new i = 0; i < len; i++)
 {
    if (i + 1 == hyphenpos)
    {
      plate[i] = '-';
      continue;
    }
    if (random(2)) // letter or number?
    { // letter
      plate[i] = 'A' + random(26);
    }
    else
    { // number
      plate[i] = '0' + random(10);
    }
 }
	printf("randomPlate 7: %s", plate);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)