Random PIN
#1

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

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.
Reply
#3

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"
Reply
#4

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

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

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

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

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...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)