473,795 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ID Card number generator


Hi,

I have to make a program which will generate 100,000 different ID
numbers (for example 2345-9341-0903-3432-3432 ...) It must be really
different, I meen it can not be a similar (like
2345-9341-0903-3432-343<b>1</b>) Does exist some algorithm for that...

Thanks.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
6 7362
On Tue, 21 Oct 2003 06:53:13 -0700, Jovo Mirkovic <yo**@sezampro. yu>
wrote:

Hi,

I have to make a program which will generate 100,000 different ID
numbers (for example 2345-9341-0903-3432-3432 ...) It must be really
different, I meen it can not be a similar (like
2345-9341-0903-3432-343<b>1</b>) Does exist some algorithm for that...

Thanks.


Consider the maximum number of IDs - 100000. That's 6 decimal digits.
Your format indicated that you want a string of four-digit numbers
separated by "-" signs. (Even if that's not the case, I'll use it to
demonstrate the principal.)

So let's say the output format is:
DDDD-DDDD-DDDD-DDDD-DDDD

We could convert our integer (the counter going from 1 to 100000) into
an ASCII string with leading zeros, and cut each character and place
it into a particular position in the output string.

e.g.
D1D2-D34D-DDDD-D5DD-D6DD
(The numbers indicate the digit positions on the input string)

The "D" digits could therefore be filled with random data. See that?

Ok, you can actually do something more useful than simply using random
data. You can use that extra bandwidth for testing the validity of the
original number.

In the example I gave, there are 14 digit spaces that we can make use
of (the D positions without the numbers in).

Taking our original number, we can then produce a hash (SHA, MD5 etc.)
of that value. Then convert it to an ASCII string (padding or cutting
the end if necessary) so that it has 14 digits. We can then insert
those digits into the empty positions. When we parse the number (and
extract the number digits) we can then apply the same hash and test
that the hash matches.

As an additional note: 14 digits for a "checksum" is a little extreme.
If we reduce that number to 6, we are left with 8 digits that are now
redundant. We can reserve those for future expansion (supporting more
than 100000 IDs). The most useful thing we can do is to introduce a
"format version code" - a single digit number that will appear in the
first position.

This leads to a well-known method of allocating IDs:

1) We need to identify the version of the ID format
2) We need to encode the original numeric value
3) We need to encode a checksum of that value

e.g.:

Example: 1162-2341-2763-1532-1623
Version: 1... .... .... .... ....
Number: .1.2 .34. .... .5.. .6..
Hash: ..6. 2..1 27.. 1... ....
Unused: .... .... ..63 ..32 1.23

We could parse that number and immediately see that it is in "format
1". We therefore know where the digits for the number and the digits
for the hash are.
i.e. Format=1 Number=123456 Hash=621271 (The rest are unused - random)

Probably more than you're after, but if you're thinking about the
format, you might as well think about its future too...

Rgds,

Nov 20 '05 #2
Hi Jovo,

You could use the random number generators in VB amd .NET.

VB gives you
Rnd

This will give you one random number at a time.

.NET gives you
System.Random
System.Security .Cryptography.R NGCryptoService Provider

These two can both give you an array of random bytes which you can then
use Mod and Chr on.

This last one, despite its forbidding name is simply a very good Random
Number Generator designed for even distribution of values. (Rnd and Random are
not as rigorous)

If you are doing 100,000 Ids, I would use a StringBuilder as shown in the
code below. You might even consider creating your sbId outside the function
and reusing it by passing it in each time.

Regards,
Fergus

<code>
Imports System.Text
Imports System.Security .Cryptography

Public Function CreateId As String
Const NumDigits As Integer = 24 'Excluding the '-'

Dim oRNGCryptoServi ceProvider As New RNGCryptoServic eProvider
Dim aBytes (NumDigits) As Byte
oRNGCryptoServi ceProvider.GetB ytes (aBytes)

Dim sbId As New StringBuilder (NumDigits * 2) 'More than enough.
Dim I As Integer

'Create group of four digits with a '-' between.
For I = 1 To NumDigits
sbId.Append (Chr (Asc("0") + aBytes(I) Mod 10))
If (I Mod 4) = 0 Then _
sbId.Append ("-")
Next

sbId.Remove (sbId.Length - 1, 1) 'Remove the trailing '-'.

Return sbId.ToString
End Function
</code>
Nov 20 '05 #3


Thanks. It was very useful to me...

Jovo

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
On Tue, 21 Oct 2003 19:02:42 +0100, "Fergus Cooney" <fi*****@post.c om>
wrote:
Hi Jovo,

You could use the random number generators in VB amd .NET.

VB gives you
Rnd

This will give you one random number at a time.

.NET gives you
System.Random
System.Security .Cryptography.R NGCryptoService Provider

These two can both give you an array of random bytes which you can then
use Mod and Chr on.

This last one, despite its forbidding name is simply a very good Random
Number Generator designed for even distribution of values. (Rnd and Random are
not as rigorous)

If you are doing 100,000 Ids, I would use a StringBuilder as shown in the
code below. You might even consider creating your sbId outside the function
and reusing it by passing it in each time.

Regards,
Fergus

<code>
Imports System.Text
Imports System.Security .Cryptography

Public Function CreateId As String
Const NumDigits As Integer = 24 'Excluding the '-'

Dim oRNGCryptoServi ceProvider As New RNGCryptoServic eProvider
Dim aBytes (NumDigits) As Byte
oRNGCryptoServi ceProvider.GetB ytes (aBytes)

Dim sbId As New StringBuilder (NumDigits * 2) 'More than enough.
Dim I As Integer

'Create group of four digits with a '-' between.
For I = 1 To NumDigits
sbId.Append (Chr (Asc("0") + aBytes(I) Mod 10))
If (I Mod 4) = 0 Then _
sbId.Append ("-")
Next

sbId.Remove (sbId.Length - 1, 1) 'Remove the trailing '-'.

Return sbId.ToString
End Function
</code>


Perhaps I've missed something in MS implementation of an RNG... just
because it provides a near even distribution, you are certainly not
guaranteed that duplicates are not output - in fact, you are going to
get them. Moreover, the "mod 10" actually reduces the keyspace by a
factor of 25 for each byte. Therefore, you cannot say that this
algorithm provides the "different ID" requirement.

Rgds,
Nov 20 '05 #5
Hi Andy,

Doh!.

Quick - Add in your 000001 to 100000 bit and make a workable solution
before Jovo goes away. I'm off to bed.. ;-)

Regards,
Fergus
Nov 20 '05 #6
* "Fergus Cooney" <fi*****@post.c om> scripsit:
I'm off to bed.. ;-)


;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
12958
by: JC | last post by:
I am very new to programming and learning on my own. Why do I keep getting duplicate values using this code? I want to shuffle a deck of 52 cards. The logic seems right to me. Randomize For C = 0 To 1000 C1 = Cards(Int(Rnd * 52)) ' returns a number from 0 to 51
10
4155
by: dries | last post by:
A friend of mine has a problem with his credit card validation routine and it is probably a simple thing to solve but I cannot find it. It has to do with the expiry dates. What happens is that as each month passes, that month is then not recognised as being valid, even though the year makes it still valid. i.e. the number of the month entered has to be bigger than the number of the current month. Therefor, if it is in august now 09/2005...
5
3353
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...
1
7823
by: Bill D'Innocenzo | last post by:
There are many functions available that implement credit card identification and number validation -- meaning you can decide, based on the number, if a card is a MasterCard or Visa and if the number passes the Luhn Formula or MOD 10 algorithm for the checksum. What I'm looking for however is the scheme to determine is a card is a check or debit card versus a credit card. Anyone know if this can be done by examining the account number...
3
2341
by: larry | last post by:
Hi, my friends, My boss asked me to use sound card to do analog to digital conversion for my application. I know when we record sound, sound card changes anolog signal to digital file. I have no idea where should I start? Do I need to write a driver for sound card? Is there any tool from Visual Stuido? Would you like to help me? H e l p ! Regards,
0
2256
by: bohuge | last post by:
Hey! At the time being I'm working on a backup solution for a Qtek9090 pocketpc, which should be able to find and backup outlook data to a server, local files, messages and contact from the sim card (and backup them to a server as well) all written in C#. So I'm making a wrapper for the sim manager api. In order to use it's functions in my device application, I've used platform invoke method, to acces the simmanager functions from...
0
3014
by: Limpor | last post by:
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can someone helps me. Thanks!! ----------------------------------------------------------------------- The code for the Stock class: ----------------------------------------------------------------------- public class Stock { private Deck deck = new...
11
2489
by: Paul Furman | last post by:
I'm setting up credit card payment through authorize.net and they have the option to send a POST string back to my site once complete. I'm not sure how to proceed. They don't have much to read about this, their tech support seemed to think I've got the general idea though & said I might have have my hosting server set up permissions to recieve POST data that way. Let me paste their explanation: ----------- Gateway Response API
2
3348
by: rubyhuang | last post by:
the problem is A standard pack of cards can be represented as an array of 52 integers with each number representing a standard card. Thus: 0 1 2 3 4 5 6 7 8 9 10 11 12.....39 40 41 42 43 44 45 46 47 48 49 50 51 We can shuffle this pack of cards by randomly generating two indexes and swapping those two cards. For example if we randomly generate the indexes 8 and 50 and swap these two "cards" we would get (assuming this is the first swap): 0...
0
9673
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
10448
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...
0
10217
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
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
10003
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
9046
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6784
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
5440
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...
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.