want to take some digital stationary random extracted,34,35 (from 1 to 19, and 33), and not when the second random sampling randomly selected for the first time to the number, the third time random don't draw on the first two to digital, and so on, how to do? Consult, thank you!! CodePudding user response:
Put these Numbers in a listbox, random take a subscript, get a number, delete it, then repeat this process,
CodePudding user response:
With an array, a dictionary, and so on are very simple
Reference:
Sub Test () Dim bDic As New Dictionary, I As an Integer For I=1 To 19 BDic (CStr) (I)=I Next For I=33 To 35 BDic (CStr) (I)=I Next Randomize The Do While bDic. Count & gt; 0 I=Int (Rnd * bDic. Count) "' take a random The Debug. Print bDic. Keys (I) BDic. Remove bDic. Keys (I) 'using the delete Loop End Sub .
CodePudding user response:
refer to the second floor Topc008 response: with array, a dictionary, and so on are very simple Reference: Sub Test () Dim bDic As New Dictionary, I As an Integer For I=1 To 19 BDic (CStr) (I)=I Next For I=33 To 35 BDic (CStr) (I)=I Next Randomize The Do While bDic. Count & gt; 0 I=Int (Rnd * bDic. Count) "' take a random The Debug. Print bDic. Keys (I) BDic. Remove bDic. Keys (I) 'using the delete Loop End Sub . try and error "undefined user type", what is willing to excuse me? CodePudding user response:
refer to the second floor Topc008 response: with array, a dictionary, and so on are very simple Reference: Sub Test () Dim bDic As New Dictionary, I As an Integer For I=1 To 19 BDic (CStr) (I)=I Next For I=33 To 35 BDic (CStr) (I)=I Next Randomize The Do While bDic. Count & gt; 0 I=Int (Rnd * bDic. Count) "' take a random The Debug. Print bDic. Keys (I) BDic. Remove bDic. Keys (I) 'using the delete Loop End Sub . Dim arr (9), k, r Private Sub Command1_Click () If Command1. Caption="stop" Then Command1. The Caption="pull" the Else Command1. The Caption="stop" If arr (0)=0 Then For I=0 To 9 Arr (I)=I + 1 Next 'MsgBox "10 initialization is complete" End the If Randomize While Command1. Caption="stop" R=Int (Rnd * (10 - k)) + k If Rnd & gt; 0.2 Then TextBox1. Text="000" The Else TextBox1. Text=Right (" 00 "& amp; Arr (r), 3) End the If DoEvents Wend If Command1. Caption="out" Then T=arr (r) : arr (r)=arr (k) : arr (k)=t: k=k + 1 TextBox1. Text=Right (" 00 "& amp; T, 3) End the If If k & gt; 9 Then If Command1. Caption & lt;> "Out" Then k=0 Command1. Caption=Join (arr, "-") & amp; VbLf & amp; "Already full, the next round" The Else Command1. Caption=Left (the Join (arr. "-"), k * 2) & amp; VbLf & amp; "Have their first" & amp; K & amp; "The next one," End the If End Sub Sub OnSlideShowPageChange () Command1. Caption="start" Open. Caption="open" TextBox1. Text="000" End Sub Private Sub open _Click () ActivePresentation. SlideShowWindow. View. GotoSlide (TextBox1. Text + 1) End Sub This how to change I want that kind of results?? Please grant instruction! CodePudding user response:
Above is a little mistake, I should start from 0, another CurrentMaxIndex variable is superfluous, completely can use I, here resend, Private Sub Command1_Click () Dim s $, v, I %, rndIndex % 'going to deal with the data processing on the arrays v For I=1 To 19 S=s & amp; I & amp; " "Next For I=33 To 35 S=s & amp; I & amp; " "Next V=Split (Trim (s), "") Randomize For I=0 To UBound (v) RndIndex=Int (Rnd * (UBound (v) - I)) The Debug. Print the I & amp; VbTab & amp; "Random results:" & amp; V (rndIndex) & amp; VbTab & amp; "Corresponding to the current index:" & amp; RndIndex V (rndIndex)=v (UBound (v) - I) 'to the end of the range of the circulation index random location data to get the Next End Sub Processing result (different every time) : Zero random results: four corresponding current index: 3 1 random results: 13 corresponds to the current index: 12 Two random results: three corresponding current index: 2 3 random results: 5 corresponding current index: 4 4 random results: 7 corresponds to the current index: 6 5 random results: 6 corresponding to current index: 5 6 random results: 9 correspond to the current index: 8 7 random results: 19 corresponding to the current index: 4 8 random results: 10 corresponding current index: 9 9 random results: 35 corresponds to the current index: 3 10 random results: 1 corresponds to the current index: 0 11 random results: 12 corresponds to the current index: 0 12 random results: 16 correspond to the current index: 8 13 random results: 15 corresponds to the current index: 4 14 random results: 34 corresponds to the current index: 3 15 random results: 17 corresponds to the current index: 5 16 random results: 33 corresponds to the current index: 2 17 random results: 18 corresponds to the current index: 2 18 random results: 14 corresponds to the current index: 219 random results: 11 corresponds to the current index: 0 20 random results: eight corresponding to the current index: 0 21 random results: 2 corresponds to the current index: 0 CodePudding user response:
The refer to the original poster smok_er response: want to take some digital stationary random extracted,34,35 (from 1 to 19, and 33), and not when the second random sampling randomly selected for the first time to the number, the third time random don't draw on the first two to digital, and so on, how to do? Consult, thank you!! As a result of this is not on, so on the NTH sampling, n - 1 time before draw the number will not be extracted to, Must conform to this condition, is equivalent to shuffle, digital disturb first put into the array, access time, in turn, is ok, the problem is when after n times extraction will repeat the previous round of cycle. Such a function The Public Function GetRnd (Optional ByVal DataList As String="") As String The Static Data () As a String, the Index As an Integer Dim I As an Integer, J As an Integer, S As String If Len (DataList) & gt; 0 Then Randomize The Index=0 nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull