I put the a to z each define a number
A 1
2 B
3 C
4 D
E 5
6 F
G 7
H 8
9 I
J 10
11 K
L 12
13 M
N 14
O 15
16 P
G 17
R 18
S 19
T 20
U 21
V 22
23 W
X 24
Y 25
Z 26
Is a number 1-26 a total of 26
Declare a dim x 26 digital array (26) as int
How can I get 1-26 random disturb the 26 Numbers into chaos sequence, then put the new order in the array?
Thank you ah
CodePudding user response:
Reference:Sub test ()
As String, Dim w1 and w2 As String, As an Integer k
W1="abcdefghijklmnopqrstuvwxyz"
Do
If Len (w1)=1 Then Exit the Do
K=Int (Rnd * Len (w1)) + 1
W2=w2 & amp; Mid $(w1, k, 1)
W1=Left $(w1, k - 1) & amp; Right $(w1, Len (w1) - k)
Loop
W2=w2 & amp; W1
The Debug. Print w2
End Sub
.
CodePudding user response:
Sub Main ()
Dim x (1 To 26) As an Integer
Dim As Long I
Dim j As Long
Dim temp As Integer
'initialize array'
For I=1 To 26
X (I)=I
Next
'shuffle algorithm, that is, random exchange'
Randomize
For I=1 To 26
J=1 + Int (Rnd () * 26)
Temp=x (I)
X (I)=x (j)
X (j)=temp
Next
'output'
For I=1 To 26
The Debug. Print I, x (I)
Next
End Sub