08.05.2011, 18:02
pawn Код:
random(26) + 'A'
random(26) + 'A'
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);
#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;
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);