Posts: 4,695
Threads: 222
Joined: Apr 2022
Reputation:
322
06-19-2023, 11:19 PM
(This post was last modified: 06-19-2023, 11:19 PM by bplus.)
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!
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 4,695
Threads: 222
Joined: Apr 2022
Reputation:
322
06-20-2023, 09:33 AM
(This post was last modified: 06-20-2023, 09:40 AM by bplus.)
Nearly as fast but you are doing one extra swap.
But more importantly, it is less efficient, you are swapping each time with a random from whole set which can cause ripples or waves that upset a normal distribution. The wiki will confirm this but the math is quite wonky.
https://en.wikipedia.org/wiki/Fisher–Yates_shuffle see Naive method which is yours basically.
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
Thanks bplus.
I thought there would be some subtle difference, but couldn't see what it was.
But I think I'll stick to the "Naive" method - it's simpler, and, for me, simplicity is of the essence.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.)

Please visit my Website at:
http://oldendayskids.blogspot.com/
Posts: 4,695
Threads: 222
Joined: Apr 2022
Reputation:
322
(06-21-2023, 12:48 AM)PhilOfPerth Wrote: Thanks bplus.
I thought there would be some subtle difference, but couldn't see what it was.
But I think I'll stick to the "Naive" method - it's simpler, and, for me, simplicity is of the essence.
It's subtle and I can relate to sticking with things I understand.
Certainly we've all bigger fish to fry!
Thanks for checking it out and you are not alone, Steve wasn't buying the math stuff either when I posted at the other forum. Oh well... carry on
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever