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



Random PIN - Fjclip99 - 28.07.2014

I am doing a bank system and i want a random PIN to generate...
I would like a PIN have 4 numbers (1234)...


Re: Random PIN - Beckett - 28.07.2014

pawn Код:
new pin = 1000 + random(999);
I made it 1000 + 999 because so it wont reach above 2k+. If you want you can change that into random(9999) if you want more than 2k+ or w/e.


Re: Random PIN - Mauzen - 28.07.2014

Theres the random(max+1) function pawn. https://sampwiki.blast.hk/wiki/Random

To ensure it has 4 digits you could just do this:
pawn Код:
new pin = 1000 + random(9000);
Or if you want to store it as string (that would be better anyways considering that you probably want to check the pin in a cmd or something) you can also make it start with a 0:
pawn Код:
new pin[4];
format(pin, 4, "%04d", random(10000));
The %04d in the format means "print 4 digits of the integer and fill empty spaces with 0"


Re: Random PIN - ViniBorn - 29.07.2014

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
pawn Код:
new pin = 1000 + random(999);
1000+998 = 1998


Re: Random PIN - Beckett - 29.07.2014

Quote:
Originally Posted by ViniBorn
Посмотреть сообщение
1000+998 = 1998
You're aware it's 1000 plus a randomized number between 0 and 998?


Re: Random PIN - ViniBorn - 29.07.2014

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
You're aware it's 1000 plus a randomized number between 0 and 998?
Quote:
Originally Posted by Fjclip99
Посмотреть сообщение
[...]a random PIN to generate...
I would like a PIN have 4 numbers (1234)...
2000 = 4 numbers
3000 = 4 numbers
9999 = 4 numbers


Re: Random PIN - Beckett - 29.07.2014

So what now. You're really going off topic. He can make it 9999 if he wants what's the big deal.


Re: Random PIN - Ihateyou - 29.07.2014

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
So what now. You're really going off topic. He can make it 9999 if he wants what's the big deal.
what hes saying is yes hes aware...