473,395 Members | 1,846 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,395 software developers and data experts.

generate 6 digit unique id

Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.

Any idea on which algorithm or encryptor should I have to use?

Thanks in advance,

Marc Soleda

Jun 28 '07 #1
8 7162
Does "cannot check in a database or something like that..." preclude checking
a dictionary for the 6 character key? If so, why put the constraint on
yourself. You haven't said what the maximum number of strings you will send
that need to be unique. As you approach 36^7 strings, your chance for
uniqueness diminishes, though that will be far off.

"Marc" wrote:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.

Any idea on which algorithm or encryptor should I have to use?

Thanks in advance,

Marc Soleda

Jun 28 '07 #2
The thing is that this string must be sent to a printing device.
Imagine: an inkjet printer that prints each string on bottles. this
number will be used for a daily lottery, that's why it has to be daily
unique. Each day I will reset the counter and, at most, I'll have to
print 400000 units.
The reason why I don't want to check any database and that I prefer an
algorith is because I have to transmit between 6 ad 7 string per
minute sincronized with the bottles speed so I can't lose time
querying the database.

Marc

On 28 jun, 23:52, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
Does "cannot check in a database or something like that..." preclude checking
a dictionary for the 6 character key? If so, why put the constraint on
yourself. You haven't said what the maximum number of strings you will send
that need to be unique. As you approach 36^7 strings, your chance for
uniqueness diminishes, though that will be far off.

"Marc" wrote:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.
Any idea on which algorithm or encryptor should I have to use?
Thanks in advance,
Marc Soleda- Ocultar texto de la cita -

- Mostrar texto de la cita -

Jul 5 '07 #3

"Marc" <ms*********@yahoo.eswrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
The thing is that this string must be sent to a printing device.
Imagine: an inkjet printer that prints each string on bottles. this
number will be used for a daily lottery, that's why it has to be daily
unique. Each day I will reset the counter and, at most, I'll have to
print 400000 units.
The reason why I don't want to check any database and that I prefer an
algorith is because I have to transmit between 6 ad 7 string per
minute sincronized with the bottles speed so I can't lose time
querying the database.

Marc

On 28 jun, 23:52, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
>Does "cannot check in a database or something like that..." preclude
checking
a dictionary for the 6 character key? If so, why put the constraint on
yourself. You haven't said what the maximum number of strings you will
send
that need to be unique. As you approach 36^7 strings, your chance for
uniqueness diminishes, though that will be far off.

"Marc" wrote:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.
Any idea on which algorithm or encryptor should I have to use?
Thanks in advance,
Marc Soleda- Ocultar texto de la cita -

- Mostrar texto de la cita -

Sorry I have followed entire conversation but perhaps each day you could
create a new list of numbers offline to the process. They could be stored
in any number of places XML/Database etc and when you do you processing you
can then extract the numbers one at a time. Since you are doing the
sequence creation during "non-print" time you can make it as durable as
possible.

Hope this helps
Lloyd Sheen

Jul 5 '07 #4
On 5 jul, 17:55, "Lloyd Sheen" <a...@b.cwrote:
"Marc" <msoleda2...@yahoo.eswrote in message

news:11**********************@o61g2000hsh.googlegr oups.com...


The thing is that this string must be sent to a printing device.
Imagine: an inkjet printer that prints each string on bottles. this
number will be used for a daily lottery, that's why it has to be daily
unique. Each day I will reset the counter and, at most, I'll have to
print 400000 units.
The reason why I don't want to check any database and that I prefer an
algorith is because I have to transmit between 6 ad 7 string per
minute sincronized with the bottles speed so I can't lose time
querying the database.
Marc
On 28 jun, 23:52, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
Does "cannot check in a database or something like that..." preclude
checking
a dictionary for the 6 character key? If so, why put the constraint on
yourself. You haven't said what the maximum number of strings you will
send
that need to be unique. As you approach 36^7 strings, your chance for
uniqueness diminishes, though that will be far off.
"Marc" wrote:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.
Any idea on which algorithm or encryptor should I have to use?
Thanks in advance,
Marc Soleda- Ocultar texto de la cita -
- Mostrar texto de la cita -

Sorry I have followed entire conversation but perhaps each day you could
create a new list of numbers offline to the process. They could be stored
in any number of places XML/Database etc and when you do you processing you
can then extract the numbers one at a time. Since you are doing the
sequence creation during "non-print" time you can make it as durable as
possible.

Hope this helps
Lloyd Sheen- Ocultar texto de la cita -

- Mostrar texto de la cita -
There's no problem if the sequences are the same between days. The
important thing is that they are unique during each day. Even I had
enough time to query a database or xml schema I need to use sequences
of 6 alphanumeric digits that seem alphanumeric. I mean the sequences
cannot be 000001, 000002, .... 00000A, .... they shoul be 43TDZ,
P4AS33, ...
Any idea?

Thanks,
Marc

Jul 5 '07 #5
On Jul 5, 12:34 pm, Marc <msoleda2...@yahoo.eswrote:
On 5 jul, 17:55, "Lloyd Sheen" <a...@b.cwrote:
"Marc" <msoleda2...@yahoo.eswrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
The thing is that this string must be sent to a printing device.
Imagine: an inkjet printer that prints each string on bottles. this
number will be used for a daily lottery, that's why it has to be daily
unique. Each day I will reset the counter and, at most, I'll have to
print 400000 units.
The reason why I don't want to check any database and that I prefer an
algorith is because I have to transmit between 6 ad 7 string per
minute sincronized with the bottles speed so I can't lose time
querying the database.
Marc
On 28 jun, 23:52, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
>Does "cannot check in a database or something like that..." preclude
>checking
>a dictionary for the 6 character key? If so, why put the constraint on
>yourself. You haven't said what the maximum number of strings you will
>send
>that need to be unique. As you approach 36^7 strings, your chance for
>uniqueness diminishes, though that will be far off.
>"Marc" wrote:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.
Any idea on which algorithm or encryptor should I have to use?
Thanks in advance,
Marc Soleda- Ocultar texto de la cita -
>- Mostrar texto de la cita -
Sorry I have followed entire conversation but perhaps each day you could
create a new list of numbers offline to the process. They could be stored
in any number of places XML/Database etc and when you do you processing you
can then extract the numbers one at a time. Since you are doing the
sequence creation during "non-print" time you can make it as durable as
possible.
Hope this helps
Lloyd Sheen- Ocultar texto de la cita -
- Mostrar texto de la cita -

There's no problem if the sequences are the same between days. The
important thing is that they are unique during each day. Even I had
enough time to query a database or xml schema I need to use sequences
of 6 alphanumeric digits that seem alphanumeric. I mean the sequences
cannot be 000001, 000002, .... 00000A, .... they shoul be 43TDZ,
P4AS33, ...
Any idea?

Thanks,
Marc
How about:

Module Module1

Public Sub Main()
For i As Integer = 0 To 100000
Console.WriteLine(GetNextString())
Next
End Sub

Dim rnd As New Random()

Public usedStrings As New List(Of String)()

Public Function GetNextString() As String

Dim theString As String = GetRandomString()

While usedStrings.Contains(theString)
theString = GetRandomString()
End While

usedStrings.Add(theString)
Return theString

End Function

Public Function GetRandomString() As String
Dim rndString As String = ""

For i As Integer = 0 To 5
If rnd.Next(0, 2) = 0 Then
rndString += Microsoft.VisualBasic.Chr(rnd.Next(65,
91))
Else
rndString += Microsoft.VisualBasic.Chr(rnd.Next(48,
58))
End If
Next

Return rndString
End Function

End Module

It gets slower as it runs (as it has more strings to search in the
list), but at 6 or 7 strings a minute it would take weeks before the
pause would cause a problem.

Thanks,

Seth Rowe

Jul 5 '07 #6
On 5 jul, 18:53, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Jul 5, 12:34 pm, Marc <msoleda2...@yahoo.eswrote:


On 5 jul, 17:55, "Lloyd Sheen" <a...@b.cwrote:
"Marc" <msoleda2...@yahoo.eswrote in message
>news:11**********************@o61g2000hsh.googleg roups.com...
The thing is that this string must be sent to a printing device.
Imagine: an inkjet printer that prints each string on bottles. this
number will be used for a daily lottery, that's why it has to be daily
unique. Each day I will reset the counter and, at most, I'll have to
print 400000 units.
The reason why I don't want to check any database and that I prefer an
algorith is because I have to transmit between 6 ad 7 string per
minute sincronized with the bottles speed so I can't lose time
querying the database.
Marc
On 28 jun, 23:52, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
Does "cannot check in a database or something like that..." preclude
checking
a dictionary for the 6 character key? If so, why put the constraint on
yourself. You haven't said what the maximum number of strings you will
send
that need to be unique. As you approach 36^7 strings, your chance for
uniqueness diminishes, though that will be far off.
"Marc" wrote:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.
Any idea on which algorithm or encryptor should I have to use?
Thanks in advance,
Marc Soleda- Ocultar texto de la cita -
- Mostrar texto de la cita -
Sorry I have followed entire conversation but perhaps each day you could
create a new list of numbers offline to the process. They could be stored
in any number of places XML/Database etc and when you do you processing you
can then extract the numbers one at a time. Since you are doing the
sequence creation during "non-print" time you can make it as durable as
possible.
Hope this helps
Lloyd Sheen- Ocultar texto de la cita -
- Mostrar texto de la cita -
There's no problem if the sequences are the same between days. The
important thing is that they are unique during each day. Even I had
enough time to query a database or xml schema I need to use sequences
of 6 alphanumeric digits that seem alphanumeric. I mean the sequences
cannot be 000001, 000002, .... 00000A, .... they shoul be 43TDZ,
P4AS33, ...
Any idea?
Thanks,
Marc

How about:

Module Module1

Public Sub Main()
For i As Integer = 0 To 100000
Console.WriteLine(GetNextString())
Next
End Sub

Dim rnd As New Random()

Public usedStrings As New List(Of String)()

Public Function GetNextString() As String

Dim theString As String = GetRandomString()

While usedStrings.Contains(theString)
theString = GetRandomString()
End While

usedStrings.Add(theString)
Return theString

End Function

Public Function GetRandomString() As String
Dim rndString As String = ""

For i As Integer = 0 To 5
If rnd.Next(0, 2) = 0 Then
rndString += Microsoft.VisualBasic.Chr(rnd.Next(65,
91))
Else
rndString += Microsoft.VisualBasic.Chr(rnd.Next(48,
58))
End If
Next

Return rndString
End Function

End Module

It gets slower as it runs (as it has more strings to search in the
list), but at 6 or 7 strings a minute it would take weeks before the
pause would cause a problem.

Thanks,

Seth Rowe- Ocultar texto de la cita -

- Mostrar texto de la cita -
thanks. I'll try your module an see if it reaches the speed needed (I
wrote 6/7 string per minute but it's per second)
Anyway, the problem for this is that the sequences are random so I'd
have to store them (memory or database) to check if the new sequence
is a repeated one.

Thanks,
Marc

Jul 6 '07 #7
On Jul 6, 2:06 am, Marc <msoleda2...@yahoo.eswrote:
On 5 jul, 18:53, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Jul 5, 12:34 pm, Marc <msoleda2...@yahoo.eswrote:
On 5 jul, 17:55, "Lloyd Sheen" <a...@b.cwrote:
"Marc" <msoleda2...@yahoo.eswrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
The thing is that this string must be sent to a printing device.
Imagine: an inkjet printer that prints each string on bottles. this
number will be used for a daily lottery, that's why it has to be daily
unique. Each day I will reset the counter and, at most, I'll have to
print 400000 units.
The reason why I don't want to check any database and that I prefer an
algorith is because I have to transmit between 6 ad 7 string per
minute sincronized with the bottles speed so I can't lose time
querying the database.
Marc
On 28 jun, 23:52, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
>Does "cannot check in a database or something like that..." preclude
>checking
>a dictionary for the 6 character key? If so, why put the constraint on
>yourself. You haven't said what the maximum number of strings you will
>send
>that need to be unique. As you approach 36^7 strings, your chance for
>uniqueness diminishes, though that will be far off.
>"Marc" wrote:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed. the
string has also to seem a random one and it cannot have an apparence
of a sequence.
My first approach is to do it with a decimal counter and find
and use an encryption alghorithm that converts each 6 digit decimal
number to a 6 digit alphanumeric string so then the string should have
to be unique.
Any idea on which algorithm or encryptor should I have to use?
Thanks in advance,
Marc Soleda- Ocultar texto de la cita -
>- Mostrar texto de la cita -
Sorry I have followed entire conversation but perhaps each day you could
create a new list of numbers offline to the process. They could be stored
in any number of places XML/Database etc and when you do you processing you
can then extract the numbers one at a time. Since you are doing the
sequence creation during "non-print" time you can make it as durable as
possible.
Hope this helps
Lloyd Sheen- Ocultar texto de la cita -
- Mostrar texto de la cita -
There's no problem if the sequences are the same between days. The
important thing is that they are unique during each day. Even I had
enough time to query a database or xml schema I need to use sequences
of 6 alphanumeric digits that seem alphanumeric. I mean the sequences
cannot be 000001, 000002, .... 00000A, .... they shoul be 43TDZ,
P4AS33, ...
Any idea?
Thanks,
Marc
How about:
Module Module1
Public Sub Main()
For i As Integer = 0 To 100000
Console.WriteLine(GetNextString())
Next
End Sub
Dim rnd As New Random()
Public usedStrings As New List(Of String)()
Public Function GetNextString() As String
Dim theString As String = GetRandomString()
While usedStrings.Contains(theString)
theString = GetRandomString()
End While
usedStrings.Add(theString)
Return theString
End Function
Public Function GetRandomString() As String
Dim rndString As String = ""
For i As Integer = 0 To 5
If rnd.Next(0, 2) = 0 Then
rndString += Microsoft.VisualBasic.Chr(rnd.Next(65,
91))
Else
rndString += Microsoft.VisualBasic.Chr(rnd.Next(48,
58))
End If
Next
Return rndString
End Function
End Module
It gets slower as it runs (as it has more strings to search in the
list), but at 6 or 7 strings a minute it would take weeks before the
pause would cause a problem.
Thanks,
Seth Rowe- Ocultar texto de la cita -
- Mostrar texto de la cita -

thanks. I'll try your module an see if it reaches the speed needed (I
wrote 6/7 string per minute but it's per second)
Anyway, the problem for this is that the sequences are random so I'd
have to store them (memory or database) to check if the new sequence
is a repeated one.

Thanks,
Marc
thanks. I'll try your module an see if it reaches the speed needed (I
wrote 6/7 string per minute but it's per second)
Slight difference :-)
Anyway, the problem for this is that the sequences are random so I'd
have to store them (memory or database) to check if the new sequence
is a repeated one.
In this case they are stored in memory (the List(Of String) object)
which is much more performant than a database. This method will not be
able to keep up though - you'll need at least 1/2 million numbers each
day and I noticed significant slowdowns at 100,000. Perhaps you could
use a partially time based system - like randomly generating the first
5 digits and then making the sixth equal the hour of day it was
generated (a base 24 number). Then you would could reset the random
number list (the list of used 5 digit sequences) every hour and
significantly reduce your work load.

Thanks,

Seth Rowe
Jul 6 '07 #8
rowe_newsgroups wrote:
How about:

Module Module1

Public Sub Main()
For i As Integer = 0 To 100000
Console.WriteLine(GetNextString())
Next
End Sub

Dim rnd As New Random()

Public usedStrings As New List(Of String)()

Public Function GetNextString() As String

Dim theString As String = GetRandomString()

While usedStrings.Contains(theString)
theString = GetRandomString()
End While

usedStrings.Add(theString)
Return theString

End Function

Public Function GetRandomString() As String
Dim rndString As String = ""

For i As Integer = 0 To 5
If rnd.Next(0, 2) = 0 Then
rndString += Microsoft.VisualBasic.Chr(rnd.Next(65,
91))
Else
rndString += Microsoft.VisualBasic.Chr(rnd.Next(48,
58))
End If
Next

Return rndString
End Function

End Module

It gets slower as it runs (as it has more strings to search in the
list), but at 6 or 7 strings a minute it would take weeks before the
pause would cause a problem.

Thanks,

Seth Rowe
Use a dictionary instead of a list. It's much faster to find a key in a
dictionary than checking if a value exists in a list.

--
Göran Andersson
_____
http://www.guffa.com
Jul 7 '07 #9

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

Similar topics

10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
20
by: Drebin | last post by:
It's a long story really, but the bottom line is we need to encrypt or obfuscate a clear-text 9-digit SSN/taxpayer ID into something less than 21 characters. It doesn't need to be super-secure,...
2
by: Henry | last post by:
Hi, How can I generate an eight digit random? Can I use the staff name to generate it? May I ask is there any sample c# code to see? Thanks
11
by: Zeya | last post by:
I need to randomly generate a 16 digit hex number in C# code. How can I do this? Thanks.
8
by: mortb | last post by:
Hi, How do I write a GenerateHashcode function that will generate guaranteed unique hashcodes for my classes? cheers, mortb
9
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being...
10
by: bigbadbaud | last post by:
This code is handy, but I have a more advanced problem that I need help with. I have a database that needs some special unique numbering. Depending on the States field (combo box)...ex: XFO-IA, I...
13
by: gamernaveen | last post by:
I am coding a script , where basically the user has to enter his name , choose file , file comments if required and upload. The file comments , name , filename will be stored in the database with...
16
by: sotirac | last post by:
Wondering if there is a better way to generate string of numbers with a length of 5 which also can have a 0 in the front of the number. <pre> random_number = random.sample(, 5) # choose 5...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.