随机产生100-300的随机整数 这句表达式用VB编程肿么写啊?

发布于2022-01-12 23:10:14
4个回答
admin
网友回答2022-01-12
为了生成某个范围内的随机整数,可使用以下公式:

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

这里,upperbound 是随机数范围的上限,而 lowerbound 则是随机数范围的下限。
admin
网友回答2022-01-12
Int(Rnd * 201) + 100
admin
网友回答2022-01-12
Private Sub Command1_Click()
Dim intA(0 To 49) As Integer
Dim i As Integer
Dim j As Integer
Dim s As Integer
Dim Flag As Boolean
Dim Temp As Integer
Randomize
For i = 0 To 49
intA(i) = Int(100 * Rnd) + 1
s = s + intA(i)
Next
For i = 0 To 49
Flag = False
For j = 0 To 48
If intA(j) intA(j + 1) Then
Temp = intA(j)
intA(j) = intA(j + 1)
intA(j + 1) = Temp
Flag = True
End If
Next
If Flag = False Then Exit For
Next
MsgBox 最小值: & intA(0) & ,最大值: & intA(49) & ,平均值: & s / 50 & 。
End Sub
admin
网友回答2022-01-12
Int((300-100)*Rnd+1)+100

回到
顶部