qhnw.net
当前位置:首页 >> vB随机函数10个随机数 >>

vB随机函数10个随机数

Dim a(10) As Integer Dim s As String Private Sub Command1_Click() Dim i, j, min, t As Integer For i = 1 To 9 min = 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 i s = "" For i = 1 To 10 s = s & " " & a(i

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

参考代码: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 a(20) As IntegerFor i = 1 To 10 a(0) = Int(101 * Rnd()) '生成0~100之间的随机整数 j = i - 1 '以下是降序的插入排序 While a(j) 评论0 0 0

在窗体上放一个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

Dim XX As IntegerPrivate Sub Command1_Click()Dim D(1 To 10) As IntegerFor I = 1 To 10RandomizeD(I) = Int(Rnd * 100 + 1)Next IFor I = 1 To 10If D(I) Mod 2 = 0 ThenXX = XX + D(I)End IfNext IText1.Text = XXEnd SubPrivate Sub Form_Load()Text1.Text = ""XX = 0End 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

简单啊.建立个窗体,在上面放一个按钮,然后把下面这段代码写到按钮的click事件中,运行程序,点一下按钮就会出来一行随机数.Private Sub Command1_Click() For i = 1 To 10 x = Int(Rnd() * 10) Print x; Next i Print End Sub

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

Private Sub Form_Click() Dim a(9) As Integer, max As Integer, min As Integer, arg As Single, i As Integer Randomize For i = 0 To 9 a(i) = Int(Rnd * 100) + 1 arg = arg + a(i) If i = 0 Or a(i) > max Then max = a(i) If i = 0 Or a(i) < min Then min = a(i) Print

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