I want to do practically something very similar as described in this answer. I want to create a list of random numbers that sum up to a given target value. If I would not care about the bounds, I could use what the answer suggests:
>>> print np.random.dirichlet(np.ones(10),size=1)
[[ 0.01779975 0.14165316 0.01029262 0.168136 0.03061161 0.09046587 0.19987289 0.13398581 0.03119906 0.17598322]]
However, I want to be able to control the ranges and the target of the individual parameters. I want to provide the bounds of each parameter. For instance, I would pass a list of three tuples, with each tuple specifying the lower and upper boundary of the uniform distribution. The target
keyword argument would describe what the sum should add up to.
get_rnd_numbers([(0.0, 1.0), (0.2, 0.5), (0.3, 0.8)], target=0.9)
The output could for example look like this:
[0.2, 0.2, 0.5]
How could that be achieved?
Update:
- Normalising, i.e. dividing by the sum of all random numbers, is not acceptable as it would distort the distribution.
- The solution should work with an arbitrary number of parameters / tuples.
- As was mentioned in the comment, this question is actually very similar but in another programming language.