Random numbers
#1

Hello how to code random phone number?

i want 86{00-20}{00000-99999}

between {} random this numbers

example 860099999
Reply
#2

pawn Код:
new string[70];
format(string, sizeof(string), "86%d%d", random(20), random(99999));
That should work.
Reply
#3

but as this 86{21-50}{00000-99999} ?
Reply
#4

anyone help?
Reply
#5

EDIT: I'm a fucking idiot. Easier way.

If you want 21 to 50 do:

pawn Код:
format(string, sizeof(string), "86%d%d", (random(30)+20), random(99999));
Reply
#6

Thanks
Reply
#7

format(string, size, "86%2d%5d", (random(30)+20), random(99999));

That way you'll always get the correct amount of numbers. Otherwise you could end up with shorter numbers than others.

Note: on phone so couldn't check if it was %02d or %2d. One or the the other should work.
Reply
#8

But why im got number 1

we need example 860125455
Reply
#9

Код:
new number[200];
new skaiciai = format(number, sizeof(number), "86%2d%5d", (random(30)+20), random(99999));
						PlayerData[playerid][Tinklas] = 2;
						PlayerData[playerid][Numeris] = skaiciai;
and only im got 1

PlayerData[playerid][Numeris] this is phone number
Reply
#10

Format doesn't magically return an integer. The value was in "number" as a string. This will do what you want:

Код:
PlayerData[playerid][Tinklas] = 2;
PlayerData[playerid][Numeris] = 860000000+((21+random(30))*100000)+random(99999);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)