I just tried it and it works fine:
50.0 +- 50.0: 43.1 50.0 +- 50.0: 18.8 50.0 +- 50.0: 38.2 50.0 +- 50.0: 32.8 50.0 +- 50.0: 13.4 50.0 +- 50.0: 53.8 50.0 +- 50.0: 67.6 50.0 +- 50.0: 25.2 50.0 +- 50.0: 7.2 50.0 +- 50.0: 76.4 50.0 +- 50.0: 10.9 50.0 +- 50.0: 12.7 50.0 +- 50.0: 89.9 50.0 +- 50.0: 3.1 50.0 +- 50.0: 7.0
There is risk of getting trapped and not converging on an answer. E.g. if the first number is 99, then the second number will still be randomly generated between 0 and 100 and will be thrown out repeatedly unless it's less than 1. Ditto for the third number but in an even tighter range.
However, I think that can be avoided by constraining each random number to be in the range from (mid - sd) to min(mid + sd, remainder). In the example above, the second number would be chosen between 0 and 1. Assuming that was 0.6, then the third number would be chosen between 0 and 0.4. That would be guaranteed to converge quickly.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In reply to Re^3: Need technique for generating constrained random data sets
by xdg
in thread Need technique for generating constrained random data sets
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |