|
時間がとれなくなったので、こちらのものをそちらで加工してください。
Sub test()
Dim s1 As String: s1 = "1→2→1→4→3→2→4→1→3→4→2→3→1→2"
Dim s2 As String: s2 = "1→2→4→3→1→4→2→1→3→2→3→4→1→2"
Dim dic1 As Object
Dim dic2 As Object
Dim dic As Object
Dim j As Long
Dim k As Long
Dim ss As String
Dim s As String
Columns("A:A").NumberFormatLocal = "@"
Set dic1 = CreateObject("Scripting.Dictionary")
Set dic2 = CreateObject("Scripting.Dictionary")
s1 = Replace(s1, "→", "")
s2 = Replace(s2, "→", "")
For k = 1 To Len(s1) - 2
dic1(Mid(s1, k, 2)) = Mid(s1, k + 2, 1)
dic2(Mid(s2, k, 2)) = Mid(s2, k + 2, 1)
Next
' このDictionaryというのは、"12"→"1","21"→"4","14"→ "3" 、・・・のような、
' 直前二つの数値に対応する次の数値の組み合わせを管理するもので、
' dic1("12") とすると "1" が返るようなデータ構造です。
For j = 1 To 10 'トライアルの数
ss = "12" '作成文字列(固定の文字列を指定)
Set dic = dic1 'スタートは系列Aで。
'ランダムな位置からスタート
'If WorksheetFunction.RandBetween(1, 2) = 1 Then
' Set dic = dic1
' ss = Mid(s1, WorksheetFunction.RandBetween(1, 12), 2)
'Else
' Set dic = dic2
' ss = Mid(s2, WorksheetFunction.RandBetween(1, 12), 2)
'End If
For k = 1 To 100 - 2 '100 個からなる数字作成のため繰り返し
s = Right(ss, 2)
If s = "43" Or s = "14" Or s = "21" Then ' regime switching
If whichSequence(0.85) = 1 Then
Set dic = dic1
Else
Set dic = dic2
End If
End If
ss = ss & dic(s) '次の数字を連結する
Next
'結果出力
Cells(j, 1).Value = ss
Next
Columns("A:A").EntireColumn.AutoFit
End Sub
Function whichSequence(v As Double) As Long
If Rnd < v Then
whichSequence = 1
Else
whichSequence = 2
End If
End Function
|
|