473,561 Members | 3,281 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 7346
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
12915
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
4115
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...
5
3333
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...
1
7811
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...
3
2292
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 !...
0
2248
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...
0
2999
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:...
11
2463
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...
2
3334
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...
0
7640
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...
0
7565
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...
0
7855
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. ...
0
8079
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...
1
7611
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...
1
5466
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5182
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...
0
3595
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
888
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...

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.