I would say using the roulette selection method. I will try to give a brief explanation here. Take a line 1 unit long. Now decompose this in proportion to the probability values. So in our case, the first part will be 1.2 in length, and the next three parts will be 1/6 in length. Now try a number from 0.1 to even distribution. Since all numbers have the same probability of occurrence, the number of samples belonging to the part will be equal to the length of the piece. Therefore, ever part of the number also belongs, a sample from this vector. (I will give you the R code below, you can run it for a huge amount to check if what I am saying is true. Maybe I will not explain it very well here.)
It is called roulette selection, because another analogy for the same situation may be to take a circle and divide it into sectors, where the angle of each sector is proportional to the probability values. Now again we number the number from the uniform distribution and see in which sector it falls, and the sample from this vector with the same probability
A <- 1:207 B <- 208:386 C <- 387:486 D <- 487:586 cumList <- list(A,B,C,D) probVec <- c(1/2,1/6,1/6,1/6) cumProbVec <- cumsum(probVec) ret <- NULL for( i in 1:20000){ rand <- runif(1) whichVec <- which(rand < cumProbVec)[1] ret <- c(ret,sample(cumList[[whichVec]],1)) }
source share