In the context of polls of voting results, I want to generate random numbers with specific properties to sample the possibilities within the margin of error of the poll.
For example, suppose I have polling results:
- Party A: 34%
- Party B: 25%
- Party C: 14%
- Party D: 27%
With a margin of error of 3.2% on the poll-results.
I want to generate batches of 4 (because in this case there are 4 parties) random numbers. Obviously because voting is a zero-sum game, the numbers in the batch need to sum up to zero.
I want each element of the batch to be smaller (in absolute value) than the given margin of error of the poll-results.
An example could be: (-0.5, +1.2, +0.1, -0.8)
. All the elements sum up to zero and each element is in absolute value smaller than 3.2
, i.e. the given margin of error of the poll-results.
When generating a large amount of this kind of batches of random numbers, I would like these to have some specific statistic properties:
- The maximum of the absolute values of the elements should be uniformly distributed over
(0, error_of_margin)
(this is the easy part). - The mean of the absolute values should also be uniformly distributed over
(0, error_of_margin)
.
I tried two different approaches. I will link a gist, to not fill the question with code. https://gist.github.com/thomvil/02890ea2873eed6bb155e7dc387c9564
Does anybody have some suggestions on how I could tackle this?