[HELP] Random Numbers
#1

I'm experimenting for the first time, the random() feature in SAMP. I'm going to use it to create random license plates on dynamic vehicles. When I use the command /dvcreate, it creates a vehicle. It then will call the function Random(999) to get the first side of the license plate, and another one to get the second part. So the string would look like

pawn Код:
%d - %d
And the plate would look like (at random

pawn Код:
451 - 942
What I'm wondering, if the number reaches like 45, if I could set it to have a zero before it so it will still come out to three characters, like

pawn Код:
045 - 541
And if it is possible to not only have numbers, but have letters as well.

Help please!
Reply
#2

You could try randomstring by RyDeR`. I made a quick example:

pawn Код:
stock randomString(strDest[], strLen = 30)
{
    while(strLen--)
        strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
}
pawn Код:
CMD:printshit(playerid, params[])
{
    new plate[10], firstpart[3], secondpart[3];
    randomString(firstpart, 3);
    randomString(secondpart, 3);
    format(plate, sizeof(plate), "%s - %s", firstpart, secondpart);
    SendClientMessage(playerid, -1, plate);
    return 1;
}
Tested it in game:


just spammed /printshit and got some nice strings outputted :P
Reply
#3

pawn Код:
%3d - %3d
This is what you want if you want just numbers.

You might as well just go with the above poster's suggestion if you want letters in it too.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)