Home > Mobile >  Sonar Qube issue with Random Number Generator in C#
Sonar Qube issue with Random Number Generator in C#

Time:10-01

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);
  • Related