Generate a unique receipt number  
Author Message
lzdaddy1





PostPosted: Thu Apr 08 20:55:28 CDT 2004 Top

Visual Basic [VB] >> Generate a unique receipt number

I have a web service which is accessed by a windows forms application.
When the application submits a unit of work (a "job"), I want to return a
job receipt or tracking number back to the application.

My requirements are these:

1. The receipt number must be unique (like a guid is unique)
2. The receipt must be NON sequential.
3. If possible, I'd like it to be 10 to 12 characters long.
4. If possible, I'd like to include only uppercase letters/digits (A-Z,
0-9)

The reason I want the length to be somewhat short is because I don't want
to burden the customer with a long receipt number. There may be a web page
that allows the customer to "track" the job and I don't want them to have
to enter some really long string.

What I'm looking for is similar to a fedex tracking number. These seem to
be non-sequential and must be unique. They are about 10 to 12 digits long.

I have been experimenting with classes in thue System.Security.Cryptography
namespace as well as the various hash routines but haven't, as yet,
disconvered the "magic bullet".

Can anyone push me in the right direction?

Thanks,

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Visual Studio347  
 
 
Mike





PostPosted: Thu Apr 08 20:55:28 CDT 2004 Top

Visual Basic [VB] >> Generate a unique receipt number You can't have a string that is globally unique and shorter than a GUID.
Why would they make GUIDs so long if they didn't need to be? Fed Ex
tracking numbers aren't globally unique and it sounds like you don't really
need something that is unique like a guid is unique.

You could generate a random number between 1 and 36 and use that number as
an index into an array of A-Z and 0-9. Do that 10-12 times and you'll have
a fairly unique string. You could keep a database of the previously
generated strings to compare against. If on the rare occassion, you
generate one that was already used, you just generate another one.




> I have a web service which is accessed by a windows forms application.
> When the application submits a unit of work (a "job"), I want to return a
> job receipt or tracking number back to the application.
>
> My requirements are these:
>
> 1. The receipt number must be unique (like a guid is unique)
> 2. The receipt must be NON sequential.
> 3. If possible, I'd like it to be 10 to 12 characters long.
> 4. If possible, I'd like to include only uppercase letters/digits (A-Z,
> 0-9)
>
> The reason I want the length to be somewhat short is because I don't want
> to burden the customer with a long receipt number. There may be a web
page
> that allows the customer to "track" the job and I don't want them to have
> to enter some really long string.
>
> What I'm looking for is similar to a fedex tracking number. These seem to
> be non-sequential and must be unique. They are about 10 to 12 digits
long.
>
> I have been experimenting with classes in thue
System.Security.Cryptography
> namespace as well as the various hash routines but haven't, as yet,
> disconvered the "magic bullet".
>
> Can anyone push me in the right direction?
>
> Thanks,
>
> --
> Chris
>
> To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
> address.