I’m look at algorithms and ways to generating a 10 digit security token. I’ve tried the following:
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
var buffer = new byte[4];
rng.GetBytes(buffer);
int result = BitConverter.ToInt32(buffer, 0);
var token = Math.Abs(result).ToString();
The problem is RNGCryptoServiceProvider seems to return around 9 to 10 digits. I’ve consider add an extra random numbers if it contains less than 10 digits however I not convinced this is the best approach.
appreciate any advice or recommendations.
Just pad the result with zeros to get 10 digits. Also, you should rather use a
ulongto get the full range of 10 digits.