Home > Software engineering >  Random Numbers free combination arrangement and meet the conditions
Random Numbers free combination arrangement and meet the conditions

Time:10-05

Which master can help the younger brother ah
Is random from multiple number (there is no fixed number of four digital composition data set
The number of the data set is fixed, and the composition of data set can meet the conditions specified contains multiple
Conditions are as follows: 1. The data set (1/2/3/4 determine whether 2/5 of one of the data that contains conditions to meet the condition (meet)
2. The data set (1/2/3/4 determine whether 5/6 of one of the data that contains conditions to meet the condition (meet)
~
Keep all can all meet the conditions of combinations on a computer
The source program to write?


The more efficient the application requirements, the better


Thank you very much!

CodePudding user response:

Please clarify what kind of data and conditions...

CodePudding user response:

Digital number not only fixed
And the need of data set is composed of four Numbers and four number can be repeated in the

Satisfy the condition that
For example,
Data set of 01 02, 03 04
Conditions for the special of 01 () because the data set contains 01, so meet the conditions which satisfy one digital satisfies conditions
Conditions for 05 06 (because the data set does not include the 05 06, so does not meet the conditions)
Conditions are also a number of digital and composition of the number of Numbers is not fixed, the total number of condition is not fixed

Calculated data groups need to meet all the conditions

CodePudding user response:

With Rnd statements, plus the cycle

CodePudding user response:

Which master can help the younger brother ah
Multiple incoherent Numbers (in Numbers and the number is not fixed) random extraction of four digital data set (fixed consists of four Numbers) and four Numbers of the data set can be repeated in the

And data set composed of multiple conditions to be met (condition number and not fixed) (but conditional mode fixed)
Conditional mode is as follows:
Data set of 01 03 04 04
Condition 1 01 04 () because the data set contains 01, so meet the conditions that contains one digital satisfies conditions
Conditions for 05 06 (because the data set does not include the 05 06, so does not meet the conditions)
Conditions are also a number of digital and composition of the number of Numbers is not fixed, the total number of condition is not fixed

Calculated data groups need to meet all the conditions
Keep all can all meet the conditions of combinations on a computer program can write?


Program requirements as efficiently as possible needs detailed source code or write directly into the program


Thank you very much!

CodePudding user response:

Refer to the change:
 Sub Test1 () 
"' randomly take out four Numbers from 0 ~ 9
"' reference Microsof Scripting Runtime
Dim I As an Integer, s1 As String, t1 As String
Dim j As an Integer, Tj () As String, sDic As New Dictionary
Tj=Split (" 01 05; 05 06; 07, 08, "";" Array) 'condition, with all the conditions; Segmentation
100:
SDic. RemoveAll
S1="" "' empty string
For I=1 To 4 'cycle number 4 times take 4
T1="0" & amp; Int (Rnd * 10) "' get a random number, format 0 #
For j=0 To UBound (Tj)
If InStr (1, Tj (j), t1, vbTextCompare) & gt; 0 Then sDic (CStr (j)="ok"
Next
S1=s1 & amp; The IIf (s1 & lt;> ""," ", "") & amp; T1
Next
"Judge whether the string of the current access to meet all the conditions
For I=0 To UBound (Tj)
If Not sDic. The Exists (CStr (I)) Then GoTo 100 'to get
Next
The Debug. Print s1 'output qualified string
End Sub

.

CodePudding user response:

To a function, then calls the reference code below:
 
Sub test ()
"' call this
The Debug. Print GetRndStr (" 05 06; 07 01, 02, 03 05 ")
End Sub

The Function GetRndStr (ByVal bTJ As String)
"' randomly take out four Numbers from 0 to 100
'bTJ - for input conditions, with between multiple conditions; Segmentation
"' reference Microsof Scripting Runtime
If Len (bTJ)=0 Then the Exit Function
Dim I As an Integer, s1 As String, t1 As String
Dim j As an Integer, Tj () As String, sDic As New Dictionary
Tj=Split (bTJ, ";" Array) 'condition, with all the conditions; Segmentation
100:
SDic. RemoveAll
S1="" "' empty string
For I=1 To 4 'cycle number 4 times take 4
T1=Format $(Int (Rnd * 101), "00") ' 'get a random number, Format 0 #
For j=0 To UBound (Tj)
If InStr (1, Tj (j), t1, vbTextCompare) & gt; 0 Then sDic (CStr (j)="ok"
Next
S1=s1 & amp; The IIf (s1 & lt;> ""," ", "") & amp; T1
Next
"Judge whether the string of the current access to meet all the conditions
For I=0 To UBound (Tj)
If Not sDic. The Exists (CStr (I)) Then GoTo 100 'to get
Next
GetRndStr=s1 'qualified string
End the Function
  • Related