If $X$ and $Y$ are independent uniform random variables over $[0,1]$, what is the density function of the variable $Z=\frac{X}{X+Y}$? I got the following result:
$$f_Z(z) = \begin{cases} \frac{z^2}{2(1-z)^2}, & \text{if } 0 \le z \le \frac{1}{2} \\ \frac{1}{2}, & \text{if } \frac{1}{2} < z \le 1 \\ 0, & \text{otherwise}. \end{cases}$$
My method is as follows: I first write $Z=\frac{1}{1+Y/X}$, and then I calculate the probability function of $\frac{Y}{X}$, and this can be found here. And then I calculate $Z$'s domain and density function according to the domain and density function of $\frac{Y}{X}$ (i.e., let $W=\frac{Y}{X}$, and you can get $W=\frac{1}{Z}-1$, and substitute this into $W$'s domain and density function, you can get $Z$'s). For your convenience, the density function of $W$ is as follows: $$f_W(w) = \begin{cases} \frac{1}{2}, & \text{if } 0 \le w \le 1 \\ \frac{1}{2w^2}, & \text{if } w > 1 \\ 0, & \text{otherwise}. \end{cases}$$
However, when I use Python to generate 100000 samples of $Z$ to test the result, I get the following graph, which contradicts with the density function of $f_Z(z)$ (the $z>0.5$ part). 
The code is as follows:
import numpy as np
from matplotlib import pyplot as plt
a=np.random.rand(100000,2)
s=a.sum(1)
q=a[:,0]/s
plt.hist(q,100)
plt.show()
Where am I wrong? Did I miscalculate the density function of $Z$?