How can I generate a random variable which follows the mixture Gaussian distributions:

I found the answer and tried to simulate it, but I think it is not the right dataset I wanted.
Here is my code:
M = 100
sigma1 = matrix(c(0.2, 0, 0, 0),ncol=2)
sigma2 = matrix(c(0, 0, 0, 0.4),ncol=2)
sigma12 = matrix(c(0.2, 0.028, 0.028, 0.4),ncol=2)
U = runif(M)
b = cbind(rep(NA,M),rep(NA,M))
for (i in 1:M) {
if (U[i]<.8) {
b[i,] = c(0,0)
} else if (U[i]<.85) {
b[i,] = rmvnorm(1,sigma = sigma1)
} else if (U[i]<.9) {
b[i,] = rmvnorm(1,sigma = sigma2)
} else {
b[i,] = rmvnorm(1,sigma = sigma12)
}
}
Is there something wrong? Thanks in advance!
x = seq(-20,20,.1) truth = .8*cbind(rep(0,nrow(x)),rep(0,nrow(x)))+.05*dmvnorm(x,sigma = sigma1) + .05*dmvnorm(x,sigma = sigma1) + .1*dmvnorm(x,sigma =sigma12) plot(density(d),main="Density Estimate of the Mixture Model",ylim=c(0,.2),lwd=2) lines(x,truth,col="red",lwd=2)The truth density plot is different from b density. – lele Feb 11 '22 at 14:30