4. If the equation $\cos 2 x+\sqrt{3} \sin 2 x=a+1$ has two distinct real solutions $x$ in $\left[0, \frac{\pi}{2}\right]$, then the range of the parameter $a$ is ( ).
(A) $0 \leqslant a<1$
(B) $-3 \leqslant a<1$
(C) $a<1$
(D) $0<a<1$
4. (A).

The equation can be transformed into
$$
\sin \left(2 x+\frac{\pi}{6}\right)=\frac{a+1}{2} \text {. }
$$

Since $0 \leqslant x \leqslant \frac{\pi}{2}$, we have
$\frac{\pi}{6} \leqslant 2 x+\frac{\pi}{6} \leqslant \pi$
$+\frac{\pi}{6}$. Let $t=2 x+$
$\frac{\pi}{6}$, then $\sin t=\frac{a+1}{2}\left(\frac{\pi}{6} \leqslant t \leqslant \pi+\frac{\pi}{6}\right)$ has two different
solutions. From Figure 2, we know that $\frac{a+1}{2}$ must satisfy the condition $\frac{1}{2}=\sin \frac{\pi}{6} \leqslant \sin t=$ $\frac{a+1}{2}<\sin \frac{\pi}{2}=1$, which means $1 \leqslant a+1<2$, or equivalently $0 \leqslant a<1$.