Remote API that I'm using, requires referenceId
parameter that should uniquely identify each request. I don't want to increment numbers because I might send concurrent requests and moreover, I would need to save those numbers somewhere (for example if I decide to restart the application). referenceId
should be all numbers, up to 48 characters. Could I generate a random 48-place number using RNGCryptoServiceProvider
, would that be unique?
Asked
Active
Viewed 39 times
1

nicks
- 2,161
- 8
- 49
- 101
-
Why not using GUID ? – Dimitar Tsonev Aug 04 '17 at 12:44
2 Answers
1
You can generate unique integers based on GUID. Look on that other topic : How generate unique Integers based on GUIDs

JBO
- 270
- 1
- 6
-
He has certain length requirements for the generated values, not sure if integers are enough for him or he needs different values. – Assil Aug 04 '17 at 12:48
-
1I don't know either. I jst found out that solution but maybe it's not the right one for that case. Your solution is maybe also good but i don't know if RNGCryptoServiceProvider.GetBytes gives a unique number like GUID does for sure. – JBO Aug 04 '17 at 12:50
1
Yes, That will be unique..
public static byte[] GenerateKey(int keySize)
{
using (var randomNumberGenerator = new RNGCryptoServiceProvider())
{
var randomNumber = new byte[keySize];
randomNumberGenerator.GetBytes(randomNumber);
return randomNumber;
}
}
Aside from that, Do you have a problem in storing that value?

Assil
- 572
- 6
- 21