By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

Looking for a PHP PIN Number generator

P: n/a

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

Aug 1 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

<my********@yahoo.co.uk> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

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


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

$pin = rand(1000, 9999);

Shelly

Go to: www.php.net
Aug 1 '05 #2

P: n/a
On 2005-08-01 15-56-28 Shelly <Shelly <sh************@asap-consult.com>>
wrote:
<my********@yahoo.co.uk> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

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


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

$pin = rand(1000, 9999);

Shelly

Go to: www.php.net


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/
Aug 1 '05 #3

P: n/a
Shelly wrote:
<my********@yahoo.co.uk> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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

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

$pin = rand(1000, 9999);

Shelly

Go to: www.php.net


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.
js*******@attglobal.net
==================
Aug 1 '05 #4

P: n/a
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.

Aug 2 '05 #5

P: n/a
my********@yahoo.co.uk wrote:
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.


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.
js*******@attglobal.net
==================
Aug 2 '05 #6

P: n/a
I noticed that Message-ID:
<11*********************@g14g2000cwa.googlegroups. com> from
my********@yahoo.co.uk contained the following:
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?


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/
Aug 2 '05 #7

P: n/a
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:1e********************@comcast.com...
my********@yahoo.co.uk wrote: 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 :-).


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

Shelly
Aug 2 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.