pampua84
New member
- Joined
- Mar 4, 2021
- Messages
- 2
- Programming Experience
- 3-5
Hi guys,
I'm looking for an algorithm to generate a safe random number like an OTP and I found this code on the web:
The problem is that I completely understand how this can generate a 6 digit number, so I'm not sure it's correct and I can use it.
Can someone kindly explain to me how this algorithm works and if it is correct to generate a 6 digit number?
Thanks a lot
I'm looking for an algorithm to generate a safe random number like an OTP and I found this code on the web:
Secure Random Number Generator:
const int min = 100000;
const int max = 999999;
const int elemInRange = max - min + 1;
var randomData = new byte[4];
using var rng = new RNGCryptoServiceProvider();
rng.GetBytes(randomData);
var randomInt = BitConverter.ToUInt32(randomData, 0);
var mod = randomInt % elemInRange;
var secureNumber = min + mod;
The problem is that I completely understand how this can generate a 6 digit number, so I'm not sure it's correct and I can use it.
Can someone kindly explain to me how this algorithm works and if it is correct to generate a 6 digit number?
Thanks a lot