4. A biased coin, if it is randomly tossed twice and both times it lands on heads with a probability of $\frac{1}{2}$, then the probability of getting one head and one tail when it is randomly tossed twice is $\qquad$ .
Let the probability of getting heads in a single random toss of the coin be $p$. According to the problem, we have $p^{2}=\frac{1}{2} \Rightarrow p=\frac{\sqrt{2}}{2}$. Therefore, the probability of getting one head and one tail in two random tosses of the coin is
$$
P=2 \cdot \frac{\sqrt{2}}{2} \cdot\left(1-\frac{\sqrt{2}}{2}\right)=\sqrt{2}-1 .
$$