mdsk.net
当前位置:首页 >> 产生十个随机数vB >>

产生十个随机数vB

在窗体上放一个label,Caption设为空,然后复制下面的代码就OK了.Private Sub Form_Load() Dim a(9) Randomize (Timer) For i = 0 To 9 a(i) = Rnd * 10000 Label1.Caption = Label1.Caption & a(i) & Chr(13) & Chr(10) Next End Sub

用数组来保存产生的随机数,每产生一个随机数就跟已经产生的随机数进行比较,如果跟已经产生的随机数中的一个相同的话就重新产生一个随机数,直到跟已经产生的所有随机数都不相同为止.Private Sub Command1_Click() Dim a(1 To 10)

Dim a(10) As IntegerMin = 100: Max = 1For i = 1 To 10Randomizea(i) = Int(Rnd(1) * 100 + 1)Label1.Caption = Label1.Caption & Str(a(i))Sum = Sum + a(i)If a(i) > Max Then Max = a(i)If a(i) 评论0 0 0

参考代码:Dim a(9) As Integer Randomize For i = 0 To 9 a(i) = CInt(Rnd() * 10) Next i End Sub

private sub command1_click() dim i as integer for i = 1 to 10 print int(rnd() * 90) + 10; next i printend subprivate sub form_load() command1.caption = "产生随机数"end sub

dim a as doublea=int(Rnd * (10000000000)

Private Sub Form_Load()Dim a(9) As Integer, x As Integer, k As Integer, I As IntegerRandomizeDo While I <= 9 x = Int(Rnd * 900 + 100) '**********found************* k = I If a(k) = 0 Then a(k) = x '**********found************* I = I + 1 End IfLoopFor Each y In a Debug.Print yNextEnd Sub

Dim a(10) As IntegerDim s As String Private Sub Command1_Click()Dim i, j, min, t As IntegerFor i = 1 To 9min = i For j = i + 1 To 10 If a(j) < a(min) Then min = j Next j t = a(i) a(i) = a(min) a(min) = t Next is = "" For i = 1 To 10 s = s & " " & a(i)

Private Sub Command1_Click()Dim A(9) As DoubleDim B As IntegerDim C As LongDim D As IntegerPrint "10个随机数为:"For B = 0 To 9RandomizeA(B) = Int(Rnd * 9999)Print A(B);If A(B) > C Then C = A(B): D = BNextA(D) = 0C = 0For B = 0 To 9If A(B) > C Then C = A(B)NextPrint Chr(13) & "第二大的那个数为:" & CEnd Sub

private sub command1_click() dim a(9) as integer for i = 0 to 9 way1: randomize a(i) = int(rnd() * 10) + 1 if i > 1 then for p = 0 to i - 1 if a(p) = a(i) then '与前面的对比,如果有重复,重新随机 goto way1 end if next p end if print a(i) '打印 next i end sub

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com