@H_403_0@ 大家好,我是JNFQOFFICE,本人第一次写博客,不知道如何写,请各位多多指教!
@H_403_0@ 如何产生不相同的随机数
@H_403_0@ 本人只会用VB.net,这里便用VB.NET 来编写!
@H_403_0@ private function randomff() as integer() '定义一个函数,返回为int型数组
@H_403_0@ dim a(5) as integer
@H_403_0@ randomsize()'初始化随机数
@H_403_0@ for i=0 to 5
@H_403_0@ a(i)=cint(rnd()*100)+1'产生一个1-100的数(包含1和100)
@H_403_0@ next
@H_403_0@ return a
@H_403_0@ end fubction
@H_403_0@ private function compares(byval a() as integer) as integer()'比较数组中是否有相同的随机数
@H_403_0@ for i=0 to a.length-2
@H_403_0@ for j=i+1 to a.length -1
@H_403_0@ if a(i)=a(j) then
@H_403_0@ randomsize()
@H_403_0@ a(j)=cint(rnd()*100)+1'将a(j)重新生成
a=compares(a) '如果存在就开始重新比较(迭代法)
@H_403_0@ end if
@H_403_0@ next
@H_403_0@ next
@H_403_0@return a
@H_403_0@ end function
@H_403_0@public function returnNUM () as string
@H_403_0@ dim str as string =string.empty
@H_403_0@dim a() as integer =randomff()
@H_403_0@ a=compares(a)
@H_403_0@ for i=0 to a.length-1
@H_403_0@ str &=a(i).tostring &space(5)
@H_403_0@ next
@H_403_0@return str
@H_403_0@end function