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