Generate a number that is a percentage of a max value

suggest change

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents