Generate 3 uniform random variables that add up to 0

I want to generate three random variables a, b and c such that (i) a + b + c = 0; and (ii) each of them is evenly distributed in (-1,1).

The version with two variables is simple: a = 2 * rand () - 1; B = -a. (Note: rand () is evenly distributed in (0,1))

The following solution does not work, because the range of c is too large: a = 2 * rand () - 1; b = 2 * Rand () - 1; c = -a-b.

The following solution does not work either because c is not evenly distributed: a = 2 * rand () - 1; b = 2 * Rand () - 1; c = (- a-b) / 2.

+4
source share
3 answers

You are right, there is a solution. Here is the design. Create a = 2 * rand () - 1. Now, if a <0, then let b = a + 1. Otherwise, b = a - 1. Finally, let c = - (a + b).

It is not too difficult to show that a, b and c are uniformly distributed evenly on [-1,1]. Interestingly, the solution is symmetrical in that all three pair correlations are -1/2. And you need only one call to a random generator.

+1
source

Will they be evenly distributed?

I would say roll 3 dice, but the expected value will be 10.5, which will never happen, so I'm going to say roll 3 special bones that only work from 1 to 5, and they should add up to 9.

Possible combinations:

  • 1,3,5 (* 6)
  • 1,4,4 (* 3)
  • 2.2.5 (* 3)
  • 2,3,4 (* 6)
  • 3.3.3 (* 1)

There are 6 combinations of 1,3,5 and 2,3,4, 3 combinations of 1,4,4 and 2,25 and only one combination of 3,3,3. These are 19 possible combinations (out of 125 possible scenarios).

Inside them we get these bones that roll so many times. (remember, at 2.2.5 you count 3 * for every 2, so that's 6 rolls 2).

  • 19
  • 2: 12
  • 3: 15
  • 4: 12
  • 5: 9

therefore, when the initial distribution is uniform, once you set the constraint that you see, it is no longer uniform. (Note that these numbers add to 57 as confirmation, 19 different combinations with 3 throws in each).

+1
source

Before we find out if it’s possible that you are asking, you might be interested in answering a slightly different question:

Is it possible to have three identically distributed variables a, b, c such that they always add to zero?

Answer: yes: you take, for example, three uniformly distributed variables a0, b0, c0 and with s = a0 + b0 + c0 you can get a = a0-s / 3, b = b0-s / 3 and c = c0- s / 3 with the required property. If you start with a0,b0,c0 = 1.5*rand()-0.75 , the result of a, b, c will be at [-1,1], and the distribution of a, b, c will be ok. look like this:

enter image description here

Now, if you want a, b, c to be closer to a uniform distribution compared to [-1,1], you can try something like a0,b0,c0 = 0.75*(2*rand()-1)^(1/3) , which will create a distribution for a, b, c similar to this:

enter image description here

+1
source

Source: https://habr.com/ru/post/1441245/


All Articles