SA-MP Forums Archive
Random numbers - 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 numbers (/showthread.php?tid=534182)



Random numbers - TheNerka - 28.08.2014

Hello how to code random phone number?

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

between {} random this numbers

example 860099999


Re: Random numbers - Sledgehammer - 28.08.2014

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


Re: Random numbers - TheNerka - 28.08.2014

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


Re: Random numbers - TheNerka - 28.08.2014

anyone help?


Re: Random numbers - IceCube! - 28.08.2014

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



Re: Random numbers - TheNerka - 28.08.2014

Thanks


Re: Random numbers - thefatshizms - 28.08.2014

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.


Re: Random numbers - TheNerka - 28.08.2014

But why im got number 1

we need example 860125455


Re: Random numbers - TheNerka - 28.08.2014

Код:
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


Re: Random numbers - FUNExtreme - 28.08.2014

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