Random numbers, seeds

  • Thread starter Thread starter David Sworder
  • Start date Start date
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.
 
Why you don't want to use GUIDs?
Anyway, you should take a look at RNGCryptoServiceProvider class.

HTH
Alex
 
Back
Top