471,853 Members | 844 Online

# 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?

Marc Soleda

Jun 28 '07 #1
8 6976
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?

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?
Marc Soleda- Ocultar texto de la cita -

- Mostrar texto de la cita -

Jul 5 '07 #3

"Marc" <ms*********@yahoo.eswrote in message
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?
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

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?
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
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?
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

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

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
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?
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

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

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
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?
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
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
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

Thanks,

Seth Rowe
Jul 6 '07 #8
rowe_newsgroups wrote:

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

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.

--
_____
http://www.guffa.com
Jul 7 '07 #9

### This discussion thread is closed

Replies have been disabled for this discussion.