I have used the below code to generate a random number between 0 and 1000
Random number = new Random();
number.Next(0, 1000);
But in sonarqube its an issue and is suggesting to go with this
var randomGenerator = RandomNumberGenerator.Create();
How we can pass min and max value to RandomNumberGenerator.
CodePudding user response:
Instead of Create()
, you can use the GetInt32()
method to generate a random number for specific boundaries using RandomNumberGenerator
. Please see the below example.
var randomGenerator = RandomNumberGenerator.GetInt32(0, 1000);
Console.WriteLine(randomGenerator);