Essential C# Generating Random Numbers  Suggest an edit

Generate a number that is a percentage of a max value

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.

Table Of Contents
22 Enum
107 Stream
108 Timers
145 Generating Random Numbers
  ↑ ↓ to navigate     ↵ to select     Esc to close