Return to Snippet

Revision: 33872
at October 14, 2010 16:15 by dblandin


Initial Code
int computeRandomNumber(int l, int h) {
	int randNumber;
	int range = h - l;
	randNumber = rand() % range + l + 1;
	return randNumber;
}

Initial URL

                                

Initial Description
<p>This function returns a random number within a range.</p><p>For example:</p><p>// assigns low and high values for range</p><p><code>int rangeLow = 34, rangeHigh = 78;</code></p><p>// computes a random number between 34 and 78</p><p><code>myRandomNumber = computeRandomNumber(rangeLow, rangeHigh);</code></p>

Initial Title
Random number within a range

Initial Tags
number, function

Initial Language
C++