Home > Software engineering >  Made a randomized program vb, ask god for help
Made a randomized program vb, ask god for help

Time:09-15

1. The import list file, list number according to actual
2, normal post fixed number 2 people, special post has three, the three jobs assigned number changes over a list of the number, the number of jobs in 1-2 change
3. The random grouping, researchers don't repeat
4. According to the output of the position: name

CodePudding user response:

To import, then random sequence, after coming to an end, in accordance with the requirements of the number of people you want to a few people in order to grasp a few people out

CodePudding user response:

Have three special post, please send people (at least send 1 individual)?

CodePudding user response:

 
Const workernum=20
Dim aryTestName (1 To workernum) As String
Dim As Integer I
Dim STRTMP As String
Dim idx1 As an Integer, idx2 As Integer
'simulation personnel into arrays, for example here less than 26 people, so use letters to distinguish between staff name
For I=1 To workernum
AryTestName (I)="staff" & amp; CRH (64 + I)
Next
Randomize Now () 'get a random seed

For I=1 To 10000 '10000 times random sequence order, random adjustment sequence of the number of Suggestions For more than 10 times the number of array elements
Idx1=Int (Rnd * (UBound (aryTestName) - LBound (aryTestName) + 1)) + LBound (aryTestName) 'to generate a random integer array subscript range
Idx2=Int (Rnd * (UBound (aryTestName) - LBound (aryTestName) + 1)) + LBound (aryTestName) 'generating a random integer array subscript range
'the two subscripts corresponding array element for exchange
STRTMP=aryTestName (idx1)
AryTestName (idx1)=aryTestName (idx2)
AryTestName (idx2)=STRTMP
Next

Output
'For I=LBound (aryTestName) To UBound (aryTestName)
The Debug. Print "first" & amp; Fix ((I - 1)/5) + 1 & amp; "Group" & amp; The IIf (((I - 1) Mod 5) & lt; 2, "normal jobs" & amp; ((I - 1) Mod 5) + 1, "special position" & amp; ((I - 1) Mod 5) - 1) & amp; ":" & amp; AryTestName (I)
Next


A set of output:
Group 1 normal posts 1: personnel G
Group 1 normal posts 2: personnel H
Group 1 special post 1: personnel C
Group 1 special post 2: personnel E
Group 1 special post 3: personnel T
2 set position 1: normal personnel I
Group 2 normal posts 2: personnel L
Group 2 special post 1: personnel S
Group 2 special post 2: personnel M
2 set of special post 3: personnel P
3 groups of normal post 1: personnel O
Group 3 normal posts 2: personnel F
3 set special post 1: personnel N
Group 3 special post 2: personnel D
Group 3 special post 3: personnel R
Group of normal post 1:4 staff B
4 groups of normal posts 2: personnel Q
Group 4 special post 1: personnel K
A group of special post 2 4: personnel
Set of special post 3 4: personnel J

CodePudding user response:

refer to the second floor milaoshu1020 response:
is three special post have sent (or at least send one)?

Yes, special post at least 1 person, list personnel enough just like normal post 2 people, does not meet the schedule 1 person

CodePudding user response:

reference 3 floor crispy large ice cream response:
 
Const workernum=20
Dim aryTestName (1 To workernum) As String
Dim As Integer I
Dim STRTMP As String
Dim idx1 As an Integer, idx2 As Integer
'simulation personnel into arrays, for example here less than 26 people, so use letters to distinguish between staff name
For I=1 To workernum
AryTestName (I)="staff" & amp; CRH (64 + I)
Next
Randomize Now () 'get a random seed

For I=1 To 10000 '10000 times random sequence order, random adjustment sequence of the number of Suggestions For more than 10 times the number of array elements
Idx1=Int (Rnd * (UBound (aryTestName) - LBound (aryTestName) + 1)) + LBound (aryTestName) 'to generate a random integer array subscript range
Idx2=Int (Rnd * (UBound (aryTestName) - LBound (aryTestName) + 1)) + LBound (aryTestName) 'generating a random integer array subscript range
'the two subscripts corresponding array element for exchange
STRTMP=aryTestName (idx1)
AryTestName (idx1)=aryTestName (idx2)
AryTestName (idx2)=STRTMP
Next

Output
'For I=LBound (aryTestName) To UBound (aryTestName)
The Debug. Print "first" & amp; Fix ((I - 1)/5) + 1 & amp; "Group" & amp; The IIf (((I - 1) Mod 5) & lt; 2, "normal jobs" & amp; ((I - 1) Mod 5) + 1, "special position" & amp; ((I - 1) Mod 5) - 1) & amp; ":" & amp; AryTestName (I)
Next


A set of output:
Group 1 normal posts 1: personnel G
Group 1 normal posts 2: personnel H
Group 1 special post 1: personnel C
Group 1 special post 2: personnel E
Group 1 special post 3: personnel T
2 set position 1: normal personnel I
Group 2 normal posts 2: personnel L
Group 2 special post 1: personnel S
Group 2 special post 2: personnel M
2 set of special post 3: personnel P
3 groups of normal post 1: personnel O
Group 3 normal posts 2: personnel F
3 set special post 1: personnel N
Group 3 special post 2: personnel D
Group 3 special post 3: personnel R
Group of normal post 1:4 staff B
4 groups of normal posts 2: personnel Q
Group 4 special post 1: personnel K
A group of special post 2 4: personnel
Set of special post 3 4: personnel J

Special post, a total of three, you each group has a special position, and you set the number of groups?

CodePudding user response:

reference 5 floor weixin_44797959 reply:
special post, a total of three, you this each group has a special position, and you set the number of groups?


From your description is not very understand the relationship between special and normal job you

Your question title is a randomized, give you examples of the most fundamental is the list of random disturb, another output according to my understanding of grouping algorithm,
My algorithm is each group has 5 people two normal three special, if the last group of number is not enough, then the first row is normal, more special,
If the grouping algorithm part wrong yourself to cough up,

CodePudding user response:

Can also use a dictionary and collection:
 
Option Explicit

Private mdctSpecial As New Dictionary
Private mdctCommon As New Dictionary
Private McOlSource As New Collection

Private Function GetRandomNumber (ByVal intBegin As an Integer, ByVal intEnd As Integer) As an Integer
Randomize
GetRandomNumber=Int (Rnd (intEnd - intBegin + 1) * + intBegin)
End the Function

Private Function PickFromSource () As an Integer
Dim intIndex As Integer
IntIndex=GetRandomNumber (1, McOlSource. Count)

PickFromSource=McOlSource. Item (intIndex)
McOlSource. Remove intIndex
End the Function

Private Sub GenerateSourceData ()
Dim intCount As Integer
IntCount=GetRandomNumber (3, 100)

Dim As Integer I
For I=1 To intCount
McOlSource. Add the I
Next
End Sub

Private Sub DevideIntoGroups ()
The Set mdctSpecial. Item (1)=New Collection
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related