Generate a number that is a percentage of a max value
suggest changeA 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents