Home Academia Contact Archive

PaC Exercise 3.2

Posted on February 18, 2021
import numpy as np

Exercise 3.2

Let X be a number chosen uniformly at random from [ − k, k]. Find Var[X].

Solution: If we shifted X by k + 1, we would get the uniform distribution over [1, 2k + 1]. Therefore, by exercise 3.1 we have


$$ \mathrm{Var}[X] = \frac{(2k+1)^2 - 1}{12} = \frac{4k^2 + 4k}{12} = \frac{k^2+k}{3}. $$

In particular, for k = 29 we get Var[X] = 290.

We verify this by simple sampling.

num_samples = 10**7
k = 29

samples = np.random.randint(low=-k, high=k+1, size=num_samples)

np.mean((samples - samples.mean())**2)
290.12070818521016