-
QP: Random shuffle
I've used this algorithm for random shuffing;
Make array, Card(1, 2, ... ,n)
for i=0 to n{
Generate random number j
Swap Card(i) and Card(j)
}
But I got suspicious about this algorithm recently when i did a test for new game. Is it enough for completely random shuffle? Or does anyone know more powerful algorithm?
-
Norm Wattenberger: Careful
That will create a bias if j is a number between 0 and n.
for i = n - 1 to 1 step -1
j = rnd * (i + 1)
Swap cards(i), cards(j)
next
> I've used this algorithm for random shuffing;
> Make array, Card(1, 2, ... ,n)
> for i=0 to n{
> Generate random number j
> Swap Card(i) and Card(j)
> }
> But I got suspicious about this algorithm recently
> when i did a test for new game. Is it enough for
> completely random shuffle? Or does anyone know more
> powerful algorithm?
-
QP: Thanks Norm:) That was wrong point. *NM*
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks