如何获得一个6位长随机数
根据msdn给出的公式:
int((upperbound – lowerbound + 1) * rnd + lowerbound)
6位长随机数=int((999999-100000+1)*rnd+100000)
或者,也可以这样:分别生成0-9的5个数和一个1-9的数凑起来
6位长随机数=int((9-1+1)*rnd+1)*100000+ _
int((9-0+1)*rnd+0)*10000+ _
int((9-0+1)*rnd+0)*1000+ _
int((9-0+1)*rnd+0)*100+ _
int((9-0+1)*rnd+0)*10+ _
int((9-0+1)*rnd+0)
或者也可以先用"+"连成字符串再cint
还有一个更简单的方法。六位长的?也就是说最小的是 100000 了是吗?这样:
dim r as new random()
dim n as integer = r.next(100000, 999999)
