Splitting a number
Posted: Wed Feb 06, 2013 9:12 am
Hi,
I have a requirement and a solution but I do not like it (and therefore I look for an improvement)!
The requirement is, that a have to split a number (here: 1) randomly in several parts (here: 4) and the sum of all parts have to be the initial value.
e.g.:
1 is splitted into 0.2 + 0.3 + 0.4 + 0.1
in the next run 1 is splitted into 0.3 + 0.3 + 0.2 + 0.2
and so on
The idea I came up was:
1) I use 3 (because I need 4 parts) random variables between 0 and 1 (1 because it is the number I have to split)
2) I sort the 3 random numbers (let me name it r1, r2, r3)
3) I calculate the differences between the numbers, and the differences are my final results
r1 - 0 (0 is my lower limit)
r2 - r1
r3 - r2
1 - r3 (1 is my upper limit)
What I do not like is:
- sorting is hard in Vensim PLE Plus
- it is a lot of work to extend it to more parts
Any idea how to do this job in a better / simpler way is appreciated!
Regards,
jmu
I have a requirement and a solution but I do not like it (and therefore I look for an improvement)!
The requirement is, that a have to split a number (here: 1) randomly in several parts (here: 4) and the sum of all parts have to be the initial value.
e.g.:
1 is splitted into 0.2 + 0.3 + 0.4 + 0.1
in the next run 1 is splitted into 0.3 + 0.3 + 0.2 + 0.2
and so on
The idea I came up was:
1) I use 3 (because I need 4 parts) random variables between 0 and 1 (1 because it is the number I have to split)
2) I sort the 3 random numbers (let me name it r1, r2, r3)
3) I calculate the differences between the numbers, and the differences are my final results
r1 - 0 (0 is my lower limit)
r2 - r1
r3 - r2
1 - r3 (1 is my upper limit)
What I do not like is:
- sorting is hard in Vensim PLE Plus
- it is a lot of work to extend it to more parts
Any idea how to do this job in a better / simpler way is appreciated!
Regards,
jmu