只是踢,我很快實現的洗牌在VBA,這將創建的字母A,B,C,d,E,F的隨機置換,使用Fisher-Yates - 它傳遞一個數組,並且它將洗牌它:
Public Sub Shuffle(ByRef items() As String)
Dim i, j As Integer
Dim temp As String
For i = UBound(items) To i = 1 Step -1
j = Rnd * i
temp = items(j)
items(j) = items(i)
items(i) = temp
Next
End Sub
下面的代碼創建的陣列A,B,C,d,E,F,產生200個隨機置換,並寫入它們逐行到Active表:
Public Sub WriteTests()
Dim tests(0 To 5) As String
tests(0) = "A"
tests(1) = "B"
tests(2) = "C"
tests(3) = "D"
tests(4) = "E"
tests(5) = "F"
Dim row, col As Integer
Dim mySheet As Worksheet
Set mySheet = ActiveWorkbook.ActiveSheet
For row = 1 To 200
Shuffle tests
For col = 1 To 6
mySheet.Cells(row, col).Value2 = tests(col - 1)
Next
Next
End Sub
我假設'G'分數是一個錯字。 – 2010-05-17 12:39:30
是的......抱歉。我會盡快修復它。 – coderama 2010-05-17 13:25:11
所以,爲了清楚起見,您希望能夠生成A,B,C,D,E,F隨機洗牌的行(所有字符都必須存在,但不應該重複) - 並且我認爲沒關係如果某些行是相同的(每行是隨機選擇一個隨機播放)。 – Mathias 2010-05-17 18:03:25