2009/07/02(Thu) 13:14:35 編集(投稿者)
実用性皆無だけど、カードということで遊んでみた。
Private rand As New Random()
Public Sub Shuffle()
Dim cards As New List(Of Card)
For i As Integer = 1 To 108
cards.Add(New Card(i))
Next
For i As Integer = 1 To 100
cards = HiduShuffle(cards)
'cards = RiffleShuffle(cards)
Next
For Each card As Card In cards
Console.Write(card.Value & ", ")
Next
End Sub
Private Function HiduShuffle(ByVal before As List(Of Card)) As List(Of Card)
Dim i1 As Integer = rand.Next(1, before.Count / 2)
Dim i2 As Integer = rand.Next(before.Count / 2, before.Count)
Dim after As New List(Of Card)
after.AddRange(before.GetRange(i1, i2 - i1))
after.AddRange(before.GetRange(0, i1))
after.AddRange(before.GetRange(i2, before.Count - i2))
Return after
End Function
Private Function RiffleShuffle(ByVal before As List(Of Card)) As List(Of Card)
Dim threshold As Integer = rand.Next(before.Count / 2 - 5, before.Count / 2 + 5)
Dim i1 As Integer = 0
Dim i2 As Integer = threshold
Dim after As New List(Of Card)
While (i1 < threshold And i2 < before.Count)
after.Add(before(i1))
after.Add(before(i2))
i1 += 1
i2 += 1
End While
If (i1 < threshold) Then
after.AddRange(before.GetRange(i1, threshold - i1))
End If
If (i2 < before.Count) Then
after.AddRange(before.GetRange(i2, before.Count - i2))
End If
Return after
End Function
Public Class Card
Public Value As Integer
Public Sub New(ByVal i As Integer)
Value = i
End Sub
End Class
# チェック外しちゃってた(。。;