472,146 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Looking for a PHP PIN Number generator


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
7 11669

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

Similar topics

10 posts views Thread by Sonoman | last post: by
4 posts views Thread by Wahoo | last post: by
3 posts views Thread by Joe | last post: by
70 posts views Thread by Ben Pfaff | last post: by
11 posts views Thread by Mark Rae | last post: by
5 posts views Thread by Peteroid | last post: by
73 posts views Thread by cesco | last post: by
8 posts views Thread by remlostime | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.