Random number distribution

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. ...

Get Procedural Content Generation for C++ Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.