Cleanest way to create a RANDOM, UNREPEAT-ABLE Long value???

  • Thread starter Thread starter Alan Mailer
  • Start date Start date
A

Alan Mailer

I want to periodically generate a completely new random Long value in
some code I'm writing.

The value need not be based on anything in particular, I just need to
know that if I have to generate another Long value at another time
that it is extrememly unlikely that I will generate the same Long
value that I have created before.

I assume I will need to use the 'Random' function for this. I'm
writing to ask for some feedback as to the 'cleanest/most efficient'
code for creating this random-unrepeatable value.

Thanks in advance for any feedback you'd care to share.
 
Alan Mailer said:
I want to periodically generate a completely new random Long value in
some code I'm writing.

The value need not be based on anything in particular, I just need to
know that if I have to generate another Long value at another time
that it is extrememly unlikely that I will generate the same Long
value that I have created before.

I assume I will need to use the 'Random' function for this. I'm
writing to ask for some feedback as to the 'cleanest/most efficient'
code for creating this random-unrepeatable value.

Thanks in advance for any feedback you'd care to share.

Random and unrepeatable are contradictory. Is there a reason it really
needs to be random?

If you want unique and pseudo-random, then you want to look at
Random.NextBytes() and probably ByteConverter.ConvertTo(). This can give you
four bytes from which to construct a long value. You basically need to
construct a running list<long> with the numbers used previously (or a
database) and check each new entry for previous use.
 
Back
Top