4
$\begingroup$

I want to generate $n$ random numbers $u_i \in [ 0, 2^{\kappa + 1})$ such that $\sum u_i = c$ $mod$ $2^{\kappa + 1} $, where c is a constant.
Also, taking $n - 1$ random numbers and subtracting their sum from $b \cdotp 2^{\kappa + 1} + c$, where $b \cdotp 2^{\kappa + 1}$ is the closest multiple of $\;2^{\kappa + 1}$ that is greater than sum of the $n - 1$ random numbers, to get the $n^{th}$ random number a good solution?

P.S. I want to know if there's a solution to this problem that'll ensure good statistical properties.

$\endgroup$
  • $\begingroup$ And the summation is the only criteria for u's distribution? $\endgroup$ – Paul Uszak May 20 '17 at 12:57
  • $\begingroup$ Yes, that's the only criteria. Although, I'd like to know if I can get uniformly distributed random numbers that satisfy this condition. $\endgroup$ – AdveRSAry May 20 '17 at 13:27
  • $\begingroup$ So my answer was wrong, and I don't know of a way to prove that extending the simplex idea to modular arithmetic. I'll delete it in a moment. I do think your proposed idea is a good one, but this is just speculation. The top answer here may be useful. $\endgroup$ – user47922 May 20 '17 at 20:25
4
$\begingroup$

For $i=1, \dots, n-1$, generate $n-1$ random numbers $u_i \in [0,2^{κ+1})$ and define $u_n = \left(c - \sum_{i=1}^{n-1} u_i\right) \bmod 2^{κ+1}$.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ That's the idea I proposed. I want to know if it is a good way to solve this problem because when a similar solution was posed to the problem of generating n prime numbers who have a constant sum, many people said that it is not a good way of solving that problem. $\endgroup$ – AdveRSAry May 20 '17 at 21:11
  • 1
    $\begingroup$ That's optimal. When $n>1$, it is easily proven that each $u_i$ generated is uniformly random in $[0,2^{κ+1})$: that's by construction for $u_i$ with $i<n$, and for $u_n$ that follows from the fact that $u_{n-1}$ is uniformly random in $[0,2^{κ+1})$, and$$u_n=\left(c - \sum_{i=1}^{n-2} u_i\right)-u_{n-1}\bmod2^{κ+1}$$ $\endgroup$ – fgrieu May 21 '17 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.