没事就折腾一下,各位大大有没有写过一定范围内按比例出随机数?
如:随机0~100的整数,0~30占70%,31~80占10%,81~100占20%这样?
clea nMin1 = 31 nMax1 = 80 nMin2 = 81 nMax2 = 100 nMin3 = 0 nMax3 = 30 nResult = 0 lcResult = "" For i = 0 To 100 nRang = Int((100 - 0 + 1) * Rand( ) + 0) Do Case Case nRang <=10 nResult = Int((nMax1 - nMin1 + 1) * Rand( ) + nMin1) Case Between(nRang,11,30) nResult = Int((nMax2 - nMin2 + 1) * Rand( ) + nMin2) Otherwise nResult = Int((nMax3 - nMin3 + 1) * Rand( ) + nMin3) Endcase lcResult = lcResult + Transform(nResult)+"," Endfor ?lcResult
Clea nMin1 = 31&&比例1的最小值范围 nMax1 = 80&&比例1的最大值范围 nMin2 = 81 nMax2 = 100 nMin3 = 0 nMax3 = 30 nRang1 = 20 &&比例1 nRang2 = 10 &&比例2 ?x_RandRang(nRang1,nMin1,nMax1,nRang2,nMin2,nMax2,nMin3,nMax3) Function x_RandRang(nRang1,nMin1,nMax1,nRang2,nMin2,nMax2,nMin3,nMax3) nResult = 0 lcResult = "" For i = 0 To 100 nRang = Int((100 - 0 + 1) * Rand( ) + 0) Do Case Case nRang <= nRang1 nResult = Int((nMax1 - nMin1 + 1) * Rand( ) + nMin1) Case Between(nRang,nRang1 + 1 ,nRang1 + nRang2) nResult = Int((nMax2 - nMin2 + 1) * Rand( ) + nMin2) Otherwise nResult = Int((nMax3 - nMin3 + 1) * Rand( ) + nMin3) Endcase lcResult = lcResult + Transform(nResult)+"," Endfor Return lcResult Endfunc