# Looking for a PHP PIN Number generator

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

I am looking for a script that generates PIN Numbers.

Is there one available somewhere out there? I don't mind algorithms if
they will be easy to implement in PHP.

Regards

## Re: Looking for a PHP PIN Number generator

Trivial!  If you want, say, a four digit PIN number, then you can say:

\$pin = rand(1000, 9999);

Shelly

Go to:   www.php.net

## Re: Looking for a PHP PIN Number generator

wrote:

If you want to have the area below 1000, too, the easiest way is:
substr(mt_rand(10000,19999),1);

HTH,
Simon
--
Simon Stienen <http://slashlife.org/
"What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done."
/Sherlock Holmes in A Study in Scarlet by Sir Arthur Conan Doyle/

## Re: Looking for a PHP PIN Number generator

Shelly wrote:

Pins can also start with 0, i.e. 0123.  A more correct response would be:

\$pin=substr('0000' . rand(1, 9999), -4);

It prepends '0000' to a random number between 1 and 9999 then takes the last
four characters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Looking for a PHP PIN Number generator

Looking around the web I see all sorts of theories for generation
random numbers, some of which sound pretty complicated.

Does PHP's simple command, generate something truly random?

If I generate a range of 16 digit numbers, what chances are there for a
repetition over the whole 10^16 range?

I think my demands are over the top here, I don't know if my computer
can generate that number I just want to have the warm feeling that it
won't be possible in my lifetime.

## Re: Looking for a PHP PIN Number generator

I noticed that Message-ID:
mydejamail@yahoo.co.uk contained the following:

There is always a chance of repetition if you pick a random number.
Either assign the numbers incrementally, or check no duplicate exists.
Also consider using a combination or letters and numbers.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

## Re: Looking for a PHP PIN Number generator

mydejamail@yahoo.co.uk wrote:

It's pretty random, especially if you are generating these at different times
and seed the generator based on the current time.  Then you can use general
statistics functions.  I wrote a quick program to check, and it showed you would
have to generate 117,741,003 random numbers to have a 50% chance of getting a
duplicate.

Now - if you're trying to generate them all at the same time based on one seed,
the probability might be somewhat less, but shouldn't be that much.

BTW - who cares if there are duplicates?  For instance - my bank assigns a 4
digit PIN for my ATM card.  And I KNOW they have more than 10,000 users out
there.  There are a lot of duplicates.

PINs don't need to be unique - just long enough that they can't be guessed
easily.  And I don't think someone's going to guess a 16 digit PIN in any
reasonable time, even if it is computer generated.  And you could always lock
them out after 1,000,000 consecutive failures :-).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Looking for a PHP PIN Number generator

....and who is even going to remember his OWN 16 digit pin?

Shelly