C# Language Generating Random Numbers in C# Generate a number that is a percentage of a max value

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


A common need for random numbers it to generate a number that is X% of some max value. this can be done by treating the result of NextDouble() as a percentage:

var rnd = new Random();
var maxValue = 5000;
var percentage = rnd.NextDouble();
var result = maxValue * percentage; 
//suppose NextDouble() returns .65, result will hold 65% of 5000: 3250.

Got any C# Language Question?