random number, and letter
#1

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

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;
}
Reply
#3

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)
);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)