To create a 12 digit guid?

  • Thread starter Thread starter twang090
  • Start date Start date
T

twang090

Trying to create a 12 digit "guid", but have no idea on how to, anyone
please have any thought? Thanks in advance.
 
Hello twang090,
Trying to create a 12 digit "guid", but have no idea on how to, anyone
please have any thought? Thanks in advance.

What do you mean by a 12 digit guid? A guid (see here
http://en.wikipedia.org/wiki/Guid or also here
http://en.wikipedia.org/wiki/UUID) is a 16 byte number that is typically
represented by a sequence of 32 characters, representing the 16 bytes in
hexadecimal notation. Some dashes are thrown in for good measure...

So what is it that you want to create? A 12 character random string?


Oliver Sturm
 
Thanks for reply, I really appreciate it.
You are right, what I want is to create a random string that is 12
digit length, it has to be unique and I have no idea on how to do this.


Any idea? Many thanks.
 
Take a look at the system.random class. There is a method there that will
fill a byte array with random bytes. As for uniqueness, you'll need to test
for that yourself.

Mike Ober.
 
Trying to create a 12 digit "guid", but have no idea on how to, anyone
please have any thought? Thanks in advance.

Guid g = System.Guid.NewGuid();

string s= System.Guid.NewGuid().ToString();

Is that what you're looking for? If you need to manually create a GUID I
have that code around somewhere. There's an algorithm you must follow, and
it's much easier to use the built-in guid class.
 
What about using the same format as a standard Guid.... Create a 12 Byte
array, and just increment the values in them (Assuming you will have a single
central place where you create these "Guids" and then converting the result
to Hex since each byte would have a numeric value of something between 0 and
255.

Another option would be to take the machine name and the date and time down
to the millisecond and combining that into a 12 byte array before doing the
hex conversion. (Just make sure that you application can then not create more
than one "Guid" per millisecond. Combining that with a random number may sort
you out, but you will still not be able to guarantee uniqueness, but you’ll
probably be close enough. All depends how deep you want to go.

Someone mentioned something about looking at the security namespace and (I'm
guessing) look at some hashing... but then, what are you going to hash.

Anyway, hope my ramblings help at least a little bit.

David
 
Back
Top