Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good shuffle percentage?

I'm basically new to coding for random results, but did some reading and tested out the javascript version of the Fisher-Yates algorithm (as seen on wikipedia), with an ordered list.

I ended up adding code to make sure the array was shuffled differently than its initial order, and also calculated the percentage of how many objects were shuffled to a different position by the algorithm.

So I'm wondering what might be considered a good result. Kind of a generic question. If I shuffled a deck of cards, what would be the least acceptable amount of shuffle? Right now I have mine coded to repeat the algorithm if it comes out less than 25 percent shuffled.

What do you think?

like image 288
op1 Avatar asked Dec 08 '22 01:12

op1


2 Answers

Zero. You can make any number of checks you like to make it feel more random, but even the check for the same order makes your algorithm flawed.

like image 140
Eiko Avatar answered Dec 24 '22 11:12

Eiko


If your shuffle algorithm is correctly implemented and produces a truly random shuffle (modulo your PRNG's randomness, or lack thereof), I wouldn't reshuffle at all. In particular, the fact that you don't accept random configurations that are 25+% similar to your original configuration tells an adversary that they can expect not to see any of those configurations after your shuffling completes.

like image 24
ide Avatar answered Dec 24 '22 10:12

ide