Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Collections.shuffle suitable for a poker algorithm?

Tags:

java

poker

there is a poker-system in java, that uses Collections.shuffle() on all available cards before the cards are dealt.

So a collection of 52 cards 2-9, J, Q, K, A in 4 types.

After that we Collections.shuffle().

The problem is, that it seems (until now we didn't have big statistic, it's possible that we only see a lot of statistic inferences), that the algorithm is VERY unclearly.

So, is Collections.shuffle() okay for a poker algorithm?


Answers to comments: With "unclearly" I mean it's very very mysteriq at some time. Much User complain about "it's not the same as live / other pokerrooms". I played a much with this system and must say, I agree, I see 3 Royal Flashs in under 2000 played hands in this system and live/in other pokerrooms with over 100.000 played hands I see 2 until today.

like image 553
PassionateDeveloper Avatar asked Nov 28 '22 04:11

PassionateDeveloper


2 Answers

If this is a serious poker application, where money can change hands, the short answer is NO. For something like this, you should really use a hardware source of true randomness.

The slightly longer answer is: if you can't get hardware for doing true randomness, Collections.shuffle(List, Random) might be good enough if you supply a SecureRandom. The tricky part with this solution is finding a good seed value.

UPDATE: Based on your clarification, I'd suggest you look into how you're seeding the PRNG (assuming you're already using a cryptographically secure implementation; if not, do that first). You should not be using a limited set of seeds. Other things to consider:

  • you should probably instantiate a single PRNG for each game
  • you should only be shuffling the deck between hands; from your question, it's not 100% clear that you aren't also shuffling the deck between the flop, turn, river, etc.
like image 111
Hank Gay Avatar answered Dec 09 '22 13:12

Hank Gay


The Collection.shuffle uses the O(n) implementation of the Fisher-Yates shuffling algorithm.

And the random indexes are chosen with the normal PRNG of Java, so it will be approximately uniform: every shuffle of the deck will be as much probable as every other one.

This is quite ok for what you want to do, but when you want real randomization you should introduce some real random factors (like System.currentTimeMillis() used to seed the random number generator) or something more realiable like a specialized hardware.

like image 29
Jack Avatar answered Dec 09 '22 15:12

Jack