第一个for循环中随机函数Rnd()为什么反回的值总一样?
Module Module1
Sub Main()
Dim RandomArray(20) As Single
Dim SortedArray(20) As Single
Dim Rndstring As String
Dim Rnds As Single
Dim iCount, jCount, kCount As Integer
Console.WriteLine("产生的随机数列为:")
For iCount = 1 To 20
Rnds = Rnd() * 9999 + 1
Rndstring = Format(Rnds, "###0.00")
Rnds = CSng(Rndstring)
RandomArray.SetValue(Rnds, iCount)
Console.WriteLine(Convert.ToString(RandomArray.GetValue(iCount)) & ",")
Next
'插入法排序
SortedArray(1) = RandomArray(1)
For iCount = 2 To 20
SortedArray(iCount) = RandomArray(iCount)
For jCount = 1 To iCount - 1
If RandomArray(iCount) < SortedArray(jCount) Then
For kCount = iCount - 1 To jCount Step -1
SortedArray(kCount + 1) = SortedArray(kCount)
Next
SortedArray(jCount) = RandomArray(iCount)
Exit For
End If
Next
Next
Console.WriteLine("排好序的数列是:")
For iCount = 1 To 20
Console.WriteLine(Convert.ToString(SortedArray.GetValue(iCount)) & ",")
Next
Console.WriteLine()
'利用数组对象排序
RandomArray.Sort(RandomArray)
Console.WriteLine("排好序的数组是:")
For iCount = 1 To 20
Console.WriteLine(Convert.ToString(RandomArray.GetValue(iCount)) & ",")
Next
Console.WriteLine()
Console.Read()
End Sub
End Module
第一个for循环中随机函数Rnd()为什么反回的值总一样?而有时却又不一样!