Random numbers, seeds

D

David Sworder

Hi,

Each instance of my client application will generate a 15 character
random string the first time it is run. This unique string will be used to
identify the client from that point forward. It's essential that no two
clients have the same identification string.

The random characters in the identification string are generated using
the Random class which is seeded with the current DateTime. The problem is
that it's conceivable that two clients (either on two separate machines or
on two different terminal sessions on the same machine) could generate their
IDs at precisely the same time which would lead to generation of the same 15
character ID.

Is there a better choice of a seed value that would generate numbers
that have less chance of duplication? The only foolproof method that I can
think of is to have the clients request their IDs from the server. The
server would then be generating the IDs via a single instance of the Random
class which would guarantee (practically) uniqueness.
 
A

AlexS

Why you don't want to use GUIDs?
Anyway, you should take a look at RNGCryptoServiceProvider class.

HTH
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top