Collections.shuffle 适合扑克算法吗?

发布于 2024-08-30 20:41:27 字数 409 浏览 2 评论 0 原文

java 中有一个扑克系统,它在发牌之前对所有可用的牌使用 Collections.shuffle()

所以收集了52张牌2-9、J、Q、K、A 4种类型。

之后我们Collections.shuffle()

问题是,看起来(直到现在我们还没有大的统计数据,我们可能只看到很多统计推论)该算法非常不清楚。

那么,Collections.shuffle() 适合扑克算法吗?


对评论的答复: 我所说的“不清楚”是指在某些时候它非常非常神秘。很多用户抱怨“这和现场/其他扑克室不一样”。 我玩了很多这个系统,必须说,我同意,我在这个系统中看到 2000 手以下的 3 手皇家闪光,而在现场/其他扑克室,超过 100.000 手的手牌直到今天我还看到 2 手。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

扛刀软妹 2024-09-06 20:41:27

如果这是一个严肃的扑克应用程序,金钱可以易手,那么简单的答案是否定的。对于这样的事情,您确实应该使用真正随机性的硬件源。

稍微长一点的答案是:如果您无法获得实现真正随机性的硬件,Collections.shuffle(List, Random) 可能 不错如果您提供 SecureRandom 就足够了。该解决方案的棘手部分是找到一个好的种子值。

更新:根据您的澄清,我建议您研究一下如何播种 PRNG(假设您已经在使用加密安全实现;如果没有,请先这样做)。您不应该使用有限的种子集。其他需要考虑的事情:

  • 您可能应该为每个游戏实例化一个 PRNG,
  • 您应该只在双手之间洗牌;从你的问题来看,并不是100%清楚你没有在翻牌圈、转牌圈、河牌圈等之间洗牌。

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.
深居我梦 2024-09-06 20:41:27

Collection.shuffle 使用Fisher-Yates 混洗算法 的 O(n) 实现。

并且随机索引是用 Java 的正常 PRNG 选择的,因此它将大致均匀:牌组的每次洗牌的概率与其他洗牌的概率相同。

这对于您想要做的事情来说是完全可以的,但是当您想要真正的随机化时,您应该引入一些真正的随机因素(例如用于播种随机数生成器的 System.currentTimeMillis() )或更可靠的东西就像一个专门的硬件。

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.

笙痞 2024-09-06 20:41:27

好吧,我通常讨厌人们对我这么说,但是是和不是。它与 pickrandomcard Between(1, 52) 一样好,并且在随机性方面使用 rand() 函数。

问题在于,对于处理机会或随机值的任何事情,您都需要适当的硬件,普通计算机甚至无法远程生成任何类型的真正随机结果。

编辑:如果你的扑克系统是为了好玩,这是一回事,但当涉及金钱时,人们会因为你以这种方式创造随机结果而绞死你。

Ok, I generally hate people saying this to me but yes and no. It's about as ok as pickrandomcardbetween(1, 52) and use a rand() function when it comes to randomness.

The no part is that for anything that deals with chance or random values you need proper hardware, a normal computer cannot even remotely generate a truly random result of any kind.

Edit: If your pokersystem is for playing for fun it's one thing, but when money is involved people will hang you for creating random results that way.

寂寞美少年 2024-09-06 20:41:27

我建议阅读这篇文章:

我们如何学会在线扑克作弊

作者检查了一个软件包,发现了几个缺陷。一个严重的问题是种子。如果您从 32 位种子开始(并且在洗牌期间不生成新的独立种子),则只能生成 2^32 个不同的随机序列。 52 张牌的牌组有 2^226 种可能的洗牌方式,这意味着只会产生可能的牌组顺序的一小部分。

玩家在翻牌圈知道 5 个牌位(奥马哈中为 7 个)。如果玩家知道洗牌算法,他可以根据他看到的牌猜测候选种子是什么。这让他在推断隐藏牌的概率时具有很大的优势。

I suggest reading this article:

How We Learned to Cheat at Online Poker

The authors looked at one software package and found several flaws. One serious problem was the seed. If you start with a 32-bit seed (and don't generate a new independent seed during the shuffle), you can only generate 2^32 different random sequences. There are 2^226 possible shuffles of a 52 card deck, which means only a small fraction of possible deck orderings will be produced.

A player knows 5 of the card positions (7 in Omaha) at the flop. If the player knows the shuffle algorithm he can guess what the candidate seeds were based on the cards he sees. This gives him a big advantage in deducing the probabilities of what the hidden cards are.

海之角 2024-09-06 20:41:27

如果这是涉及金钱的严肃扑克软件,那么答案是否定的。 (为此,您需要一些真正的随机性来源。)但是,对于简单的情况,它与任何其他算法一样好。

如果您想了解有关 shuffle 算法本身的更多信息,请参阅 Java 的 Collections.shuffle 是做什么的?

If this is serious poker software involving money, then the answer would be no. (For this, you would want some source of true randomness.) However, for simple circumstances, it is just about as good a solution as any other algorithm.

If you want more information about the shuffle algorithm itself, see Java's Collections.shuffle is doing what?.

内心荒芜 2024-09-06 20:41:27

问题在于随机生成的数字在统计上是随机的。这意味着洗牌的行为不像一副纸牌,因为它比现实生活中的牌组洗牌更加随机。为了获得更真实的效果,您需要模拟现实生活中洗牌的方式,例如切牌的次数等。我看到一个网站,其中有一张图表,比较了真实骰子的结果和计算机生成的结果,显示了结果有多么不同。计算机结果分布更均匀,但我似乎无法在谷歌上找到链接。

The problem is that the numbers generated by random are statistically random. It means that shuffle do not behave like a deck of cards because it is more random than a real life deck shuffle. To have something more realistic you need to simulate the way you shuffle the cards in real life, like how many times you cut and so on. I saw a site with a chart comparing the results of a real dice and computer generated results that showed how different the results were. The computer results were more equally distributed, but I can't seem to find the link on google.

难忘№最初的完美 2024-09-06 20:41:27

我可以告诉你,大型扑克网站不是这样做的。
预先洗牌可以使纸牌序列在游戏服务器某处的内存中可用,即如果您有权访问服务器主机(就像操作员一样),则可以读取它。
相反,只要需要,就会从牌组中随机挑选牌(在硬件 RNG 上使用安全随机)。当你拿到“错误”的公共牌时,有时这会让你的头脑变得混乱,因为如果你多等一毫秒再打电话,它们就会不同:)

I can tell you that this is not how the large poker sites do it.
Pre-shuffling the deck makes the card sequence available in memory in the game server somewhere, i.e. it is possible to read it if you have access to the server host (like ops have).
Instead cards are randomly picked from the deck whenever they are needed (using secure random on top of hardware RNG). This screws up your mind sometimes when you get the "wrong" community cards, because if you just had waited a millisecond longer to call they had been different :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文