Welfare lottery and sports lottery are more fire in nearly two years, and everyone discusses more in VB forums. In fact, the choice of lottery tickets is the same as the collection of subsets. The recursive algorithm of VB (although in knowing that the deposited array will speed up the arithmetic speed, I will not be able to achieve much, please advise. In addition, the efficiency is not high) Option Explicit
Private submmand1_click ()
DIM TEMP, I as long, starttime as long, endtime as longstarttime = timertemp = cmn (22, 6) endtime = timeropen "d: /mofn.txt" for binary as # 1 'write file PUT # 1, TempClose # 1
MsgBox Ubound (Split (Temp, VBCRLF)) 1 & "Composite", 64, "Shared" & EndTime - StartTime & "Second" 'Computing combination possible situation and time consuming
End Sub
Function CMN (Byval M AS Integer, Byval N as Integer) AS String 'SELECT N Number from 1 ~ Mdim A () AS String, Temp As String, I as Long
Redim a (1 to m) 'Defines an array for i = 1 to ma (i) = inext
IF m = 3 THENIF N = 1 THEN CMN = 1 & VBCRLF & 2 & VBCRLF & 3IF N = 2 THEN CMN = "1, 2" & VBCRLF & "1,3" & VBCRLF & "2, 3" IF n = 3 THEN CMN = "1, 2, 3"
Elseif M> 3 Thenif n = 1 THEN CMN = JOIN (A, VBCRLF) IF n = m THEN CMN = JOIN (A, ",") IF n> 1 and n END IF END FUNCTION The following is given to use a set implementation without repeating random selection of a number, which can also be used to implement random arrangements of all elements of array. Function Getone (Byval M AS Integer) AS String 'One Random Option To Select N Number from 1 ~ M WITHOUT REAT NUMBERDIM A () AS String, Temp As New Collection, I As Long, Tempi As Longredim A 1 to n) 'Define array for i = 1 to mTemp.add i' can be changed as needed NEXT Randomizefor I = 1 to ntempi = int (rND * Temp.count) 1A (i) = Temp (Tempi) Temp.remove TempinextGetone = Join (a, ",") set temp = NothingRase Adend Function Private Sub Command2_Click () 'Demo MsgBox getone (30, 8), 64, "30 selected 8" MSGBox getone (100, 100), 64, "1 to 100 non-repetition" End Sub