Это сделано согласно концепции лотереи в вики
Public Class LotteryNum
'This class create a set of lottery numbers in one group.
'Rule #1: Each number is from 1 to 49.
'Rule #2: No duplicates.
'Rule #3: Not ordered.
'Rule #4: In one group. (No Mega Ball number)
'Reference: http://en.wikipedia.org/wiki/Lottery
Private Shared rand As New Random
Private m As Integer = 5
Private LowLimit As Integer = 1
Private HighLimit As Integer = 49
Private mNums As List(Of Integer)
Sub New()
Dim n As Integer
mNums = New List(Of Integer)
Do While mNums.Count <= m
n = LowLimit + rand.Next(HighLimit - LowLimit + 1)
If Not (mNums.Contains(n)) Then
mNums.Add(n)
End If
Loop
End Sub
Sub New(ByVal GivenNums As Integer())
If (GivenNums.Length <> 6) Then
MsgBox("Input Lottery must contain 6 numbers ")
Exit Sub
End If
mNums = New List(Of Integer)
For Each n As Integer In GivenNums
mNums.Add(n)
Next
End Sub
Public ReadOnly Property Nums() As List(Of Integer)
Get
Return mNums
End Get
End Property
Public Overrides Function ToString() As String
Dim str As New List(Of String)
For Each n As Integer In Nums
str.Add(n.ToString)
Next
Return String.Join(", ", str.ToArray)
End Function
Public Shared Operator =(ByVal Lot1 As LotteryNum, ByVal Lot2 As LotteryNum) As Boolean
For Each n1 As Integer In Lot1.Nums
If Not (Lot2.Nums.Contains(n1)) Then
Return False
End If
Next
Return True
End Operator
Public Shared Operator <>(ByVal Lot1 As LotteryNum, ByVal Lot2 As LotteryNum) As Boolean
Return Not (Lot1 = Lot2)
End Operator
End Class
Импорт System.IO
Модуль Модуль 1
Sub Main()
Dim lot1 As New LotteryNum
Dim given As New LotteryNum(New Integer() {10, 18, 25, 33, 42, 7})
Dim myNum As New LotteryNum(New Integer() {10, 25, 33, 42, 18, 7})
Dim yourNum As New LotteryNum(New Integer() {10, 23, 33, 42, 18, 7})
Console.WriteLine("The new lottery numbers are: {0}", lot1.ToString)
Console.WriteLine("My lottery is the LOTTERY: {0}", (myNum = given))
Console.WriteLine("Your lottery is the LOTTERY: {0}", (yourNum = given))
'Generate 300 lotteries and write to file
Dim str As New List(Of String)
For i As Integer = 0 To 299
str.Add((New LotteryNum).ToString)
Next
File.WriteAllLines("c:\temp\lottery.txt", str.ToArray)
Console.ReadKey()
End Sub
Конечный модуль