473,839 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11760

<my********@yah oo.co.uk> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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********@yah oo.co.uk> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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********@yah oo.co.uk> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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('00 00' . 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*******@attgl obal.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********@yaho o.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*******@attgl obal.net
=============== ===
Aug 2 '05 #6
I noticed that Message-ID:
<11************ *********@g14g2 000cwa.googlegr oups.com> from
my********@yaho o.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*******@attg lobal.net> wrote in message
news:1e******** ************@co mcast.com...
my********@yaho o.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
2914
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 have is that the first loop I get a sequence of random numbers untuil I get a match, BUT then on the following loops I get the SAME random(?) sequence. I am using rand(). I do not want to get too fancy with the random number generator, but is there...
4
2407
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
7383
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 have utilised the following random number source code http://www.agner.org/random/ What I have found is that there is a problem with seeding. The code generates a seed based on time(0). I have found that I need to increment
70
6301
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 using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
11
1847
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 System.Threading; using System.Web.Services;
5
3355
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 double value in the range could come up with equal probability). I'd also like to be able to seed this generator (e.g., via the clock) so that the same sequence of random values don't come up every time. Anybody have an easy and fast...
73
3242
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 simple pattern or function in Python to accomplish that? Thanks and regards Francesco
20
5140
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
4731
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))
0
9856
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10913
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10656
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7022
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4067
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.