话不多说,直接上代码
getRandomNum = function(x,min,q25,q50,q75,max){
if (x%%2 == 0 & (x/2)%%2 == 0) {
tmp1 = runif(x/4-2,min,q25-1)
tmp2 = runif(x/4-2,q25+1,q50-1)
tmp3 = runif(x/4-2,q50+1,q75-1)
tmp4 = runif(x/4-2,q75+1,max)
y = c(min,tmp1,q25-1,q25+1,tmp2,q50-1,q50+1,tmp3,q75-1,q75+1,tmp4,max)
} else if(x%%2 == 0 & (x/2)%%2 != 0){
tmp1 = runif(ceiling(x/4-2),min,q25)
tmp2 = runif(ceiling(x/4-2),q25,q50-1)
tmp3 = runif(ceiling(x/4-2),q50+1,q75)
tmp4 = runif(ceiling(x/4-2),q75,max)
y = c(min,tmp1,q25,tmp2,q50-1,q50+1,tmp3,q75,tmp4,max)
} else if(x%%2 != 0 & (x-1)%%4 == 0){
tmp1 = runif((x-1)/4-1,min,q25)
tmp2 = runif((x-1)/4-1,q25,q50)
tmp3 = runif((x-1)/4-1,q50,q75)
tmp4 = runif((x-1)/4-1,q75,max)
y = c(min,tmp1,q25,tmp2,q50,tmp3,q75,tmp4,max)
} else if(x%%2 != 0 & (x-1)%%4 != 0){
tmp1 = runif(ceiling((x-1)/4-2),min,q25-1)
tmp2 = runif(ceiling((x-1)/4-2),q25+1,q50-1)
tmp3 = runif(ceiling((x-1)/4-2),q50+1,q75-1)
tmp4 = runif(ceiling((x-1)/4-2),q75+1,max)
y = c(min,tmp1,q25-1,q25+1,tmp2,q50,tmp3,q75-1,q75+1,tmp4,max)
}
return(y)
}
z = getRandomNum(x = 5,min = 2230,q25 = 18123,q50 = 52213,q75 = 78312,max = 234234123)
quantile(z)
fivenum(z)
网友评论