Fisher Yates Shuffle for cards or any number of items
#1
As discussed in Ranking Poker Hands:
Code: (Select All)
TopN = 52
ReDim n(1 To TopN) 'repeatable for ref
For i = 1 To TopN
    n(i) = i
Next
For i = TopN To 2 Step -1 ' Fisher Yates Shuffle of N Items
    Swap n(i), n(Int(Rnd * (i) + 1))
Next
For i = 1 To TopN
    Print "  "; i; "-"; n(i); Chr$(9);
Next
Print

At maximum you need only swap n-1 items!
b = b + ...
Reply


Messages In This Thread
Fisher Yates Shuffle for cards or any number of items - by bplus - 06-19-2023, 11:19 PM



Users browsing this thread: 2 Guest(s)