says I have a set of values e.g. A, B, C, D and each of them have a probability. If I want to generate these values randomly base on their assigned percentage, why can't I just generate the values base on the assigned percentages but need to use cumulative percentages?

Using cumulative percentages is not strictly necessary for random generation of values; it's simply one common and efficient method to map a single random number to a discrete probability distribution, such as the probabilities assigned to your values A, B, C, and D.

Let's consider two methods:

**Direct Comparison Method:**

1. Generate a random float between 0 and 1.
2. Check where it falls in relation to the assigned probabilities of each outcome.

For example, suppose you have the following probabilities:

- A: 10%
- B: 20%
- C: 40%
- D: 30%

You would have to perform multiple comparisons:

- If a random number is between 0 and 0.1, choose A.
- If it is between 0.1 and 0.3 (0.1 from A + 0.2 for B), choose B.
- If it's between 0.3 and 0.7 (0.1 from A + 0.2 for B + 0.4 for C), choose C.
- If it's between 0.7 and 1 (all the previous probabilities summed), choose D.

**Cumulative Probability Method:**

1. Compute the cumulative probabilities.
2. Generate a random float between 0 and 1.
3. Use a single comparison to find the first cumulative probability that the random number does not exceed.

With the cumulative probabilities, you'd have:

- A: 0.1 (10%)
- B: 0.3 (previous 10% + 20%)
- C: 0.7 (previous 30% + 40%)
- D: 1.0 (previous 70% + 30%)

Here's what you would do:

- A random number up to 0.1 yields A.
- Up to 0.3 (but greater than 0.1) yields B.
- Up to 0.7 (but greater than 0.3) yields C.
- Up to 1.0 (but greater than 0.7) yields D.

Using cumulative probabilities simplifies the process because you only need one comparison to find where your random float fits into your distribution. This is particularly beneficial when you have a large set of outcomes, as it avoids a long series of individual probability checks.

Both methods are correct and will produce the correct probability distribution for a large number of trials. The cumulative probability method can be more efficient and easier to implement, especially in situations with more outcomes or when you want to avoid multiple if-elseif conditions.