December 2017
Beginner to intermediate
470 pages
12h 29m
English
As you may remember, The Food Factory creates their foods by receiving a macronutrient specification. Customers can specify whatever combination of percentages they want for each one, as long as they add up to 1. Now we are going to simulate these macronutrient percentages. This will require a little more work than the previous cases.
First, we create a function that will return numeric triples, where each number is between 0 and 1, and together they add up to 1. To accomplish this, we will use two random numbers and make the third one dependent on the first two. We will use the following mathematical fact:
This tells us to take one number as 1 - max(a, b), another as min(a, b), and the last one ...