SA-MP Forums Archive
random number, and letter - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: random number, and letter (/showthread.php?tid=485171)



random number, and letter - audriuxxx - 03.01.2014

Hi,

I want to generate player a code, like that: yqe565 lta254 tlq621

I want three simbols will be a letters and they allways will be small, not like QWE455 RYB692 GLQ658 , and other three simbols will be a numbers


Re: random number, and letter - Konstantinos - 03.01.2014

pawn Код:
// Where you want a random one:
    new
        code[7];
   
    for (new i; i != 3; ++i) format(code, sizeof (code), "%s%c", code, RandomEx('a', 'z'));
    for (new i; i != 3; ++i) format(code, sizeof (code), "%s%c", code, RandomEx('0', '9'));
pawn Код:
stock RandomEx(min, max)
{
    return random(max - min) + min;
}



Re: random number, and letter - Vince - 03.01.2014

Why not use a single format statement? I reckon that'd be much faster?
pawn Код:
format(code, sizeof(code), "%c%c%c%d%d%d",
    RandomEx('a', 'z'),
    RandomEx('a', 'z'),
    RandomEx('a', 'z'),
    random(10),
    random(10),
    random(10)
);