Generate a number that is a percentage of a max value

suggest change

A common use of a random number is to take X% of some maximum. NextDouble() returns a value in the half-open range [0.0, 1.0), so it can be used as that fraction:

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