January 2016
Intermediate to advanced
304 pages
6h 17m
English
Let's build upon what we know about random number generation to distribute numbers randomly. We'll achieve this by first generating n numbers between 0 and 100. If we add these together we get a random total where each of our individual numbers represents a percentage of that. We can then take that percentage of our goal number to get a random portion. The following code demonstrates this and will make it clearer.
You can download the code for this program from the Packt website. It will be in the Examples folder, and the project name is random_distribution:
#include <iostream> using namespace std; // Entry method of the application. int main() { // Create and initialize our variables. int upperLimit = 0; // Output instructions. ...Read now
Unlock full access