VERSION 5.00
Begin VB.Form Form1
Caption = "生成随机数"
ClientHeight = 4185
ClientLeft = 60
ClientTop = 345
ClientWidth = 8595
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
ScaleHeight = 4185
ScaleWidth = 8595
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 360
Left = 5295
TabIndex = 0
Text = "20"
Top = 330
Width = 660
End
Begin VB.CommandButton Command3
Caption = "打印(&P)"
Height = 495
Left = 3435
TabIndex = 3
Top = 3480
Width = 1770
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 2265
Left = 195
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 1
Top = 900
Width = 8205
End
Begin VB.CommandButton Command1
Caption = "生成随机数(&B)"
Default = -1 'True
Height = 495
Left = 825
TabIndex = 2
Top = 3480
Width = 1770
End
Begin VB.CommandButton Command2
Cancel = -1 'True
Caption = "退出(&E)"
Height = 495
Left = 6060
TabIndex = 4
Top = 3480
Width = 1770
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "请输入要生成的随机数范围:1~ (1,200)"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 1095
TabIndex = 5
Top = 360
Width = 6345
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
With Text2
.Text = 20
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Private Sub Command1_Click()
Dim a(200) As Byte
Dim c(200) As Byte
Dim temp As Byte
temp = Val(Text2.Text)
Randomize Timer
For i = 1 To temp '产生随机数
c(i) = Int(Rnd * temp) + 1
k = i
For j = 1 To k - 1 '如果相同则这个数不要 重新选取
If c(j) = c(k) Then i = i - 1
Next j
Next i
For i = 1 To temp
Text1.Text = Text1.Text & c(i) & ","
'If i Mod 10 = 0 Then
' Text1.Text = Text1.Text & Chr(13) + Chr(10)
'End If
Next i
Text1.Text = Text1.Text & Chr(13) + Chr(10)
With Text1
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Private Sub Command3_Click()
On Error GoTo 100
Printer.Print Text1.Text
100
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Text2_Change()
If Val(Text2.Text) < 1 Or Val(Text2.Text) > 200 Then
With Text2
.Text = 20
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
Private Sub Text2_GotFocus()
With Text2
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
For K = 1 To 3
bUser = False
Do While Not bUser
bUser = True
dUserSERV(0) = dSERV(Int(iSERV * Rnd + 1))
For L = 1 To 3
If dUserSERV(0) = dUserSERV(L) Then bUser = False
Next L
bUser = Not bUser
Loop
dUserSERV(K) = dUserSERV(0)
Next K
以上程序是从dSERV(iSERV) (其中iSERV)为你的总数及你的m,随机提取三个数我想这个三就是你的n了。而且这三个数保证都是不重复的了!给你试一试吧!是我春节后才作的。