473,411 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 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 11736

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sonoman | last post by:
Hi all: I am trying to write a simple program that simulates asking several persons their birth day and it counts how many persons are asked until two have the same birth day. The problem that I...
4
by: Wahoo | last post by:
Another question,my teacher gave me a code for generate a random number from 1 - range, but I can't made it work, where is the problem? Thanks!!
3
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
11
by: Mark Rae | last post by:
Hi, My R&D department has asked me to look at threading in a Web Service written in C#, so I came up with the following code: using System; using System.ComponentModel; using...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
73
by: cesco | last post by:
I have to generate a list of N random numbers (integer) whose sum is equal to M. If, for example, I have to generate 5 random numbers whose sum is 50 a possible solution could be . Is there a...
20
by: A | last post by:
Hi all. Is this a bug or what??? here is a simple code: <?php mt_srand(1); echo mt_rand(0, 255)."<br />"; echo mt_rand(0, 255)."<br />";
8
by: remlostime | last post by:
i use g++ to generater rand number, now i find that the RAND_MAX is 32367 in my computer, how can i make a bigger rand number( the number is wihin in the integer(2^32-1))
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.