in

Find all possibilities of a percentage distribution (2 floating points) for do something for each case


Here is the problem, i need to run a function for each percentage possibility (2 floating points). So for that, i need an algorithm that identify each case for n elements.
For example:
An array of 2 elements would have the following distribution:

[1.00, 0.00]
[0.99, 0.01]
[0.98, 0.02]
[0.97, 0.03]
[...]

But in cases of more elements, this is more complexity:

[1.00, 0.00, 0.00, 0.00]

[0.99, 0.01, 0.00, 0.00]
[0.99, 0.00, 0.01, 0.00]
[0.99, 0.00, 0.00, 0.01]

[0.98, 0.02, 0.00, 0.00]
[0.98, 0.01, 0.01, 0.00]
[0.98, 0.01, 0.00, 0.01]
[0.98, 0.00, 0.02, 0.00]
[0.98, 0.00, 0.01, 0.01]
[0.98, 0.00, 0.00, 0.02]

[0.97, 0.03, 0.00, 0.00]
[0.97, 0.02, 0.01, 0.00]
[0.97, 0.02, 0.00, 0.01]
[0.97, 0.01, 0.02, 0.00]
[0.97, 0.01, 0.00, 0.02]
[0.97, 0.01, 0.01, 0.01]
[0.97, 0.00, 0.03, 0.00]
[0.97, 0.00, 0.00, 0.03]
[0.97, 0.00, 0.02, 0.01]
[0.97, 0.00, 0.01, 0.02]
[...]

Does anyone know a way to find these cases for n elements?
Its not necessary to save the array in memory, i just run a function or a part of code for each one of these cases.
This code/function could be just a print of the case.

I accept any language for response, thanks for your attention.



Source: https://stackoverflow.com/questions/70606911/find-all-possibilities-of-a-percentage-distribution-2-floating-points-for-do-s

WordPress vs Ghost – Which Is the Better Blogging Platform?

An open platform to connect, manage, and secure microservices