MySQL 的 RAND() 是否足以进行“洗牌”?纸牌游戏的纸牌组?

发布于 2024-10-18 14:46:53 字数 139 浏览 0 评论 0原文

我有一个扑克和二十一点游戏,它在 MySQL 数据库中存储一组基本牌。为了洗牌,我使用 ORDER BY RAND() 对表进行随机排序,并按该顺序将牌插入到另一个表中。使用 RAND() 是否会导致使用真实纸牌和物理洗牌时出现的实际赔率,或者该函数是否不够随机?

I've got a poker and blackjack game that store a base card deck in a MySQL database. In order to shuffle the cards, I order the table at random using ORDER BY RAND() and insert the cards in that order into a different table. Will using RAND() result in realistic odds that would be found playing with real cards and physically shuffling, or is this function not random enough?

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

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

发布评论

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

评论(2

过去的过去 2024-10-25 14:46:53

除非你经常练习,否则用真牌洗牌并不是那么随机。很容易错误地洗牌,导致牌堆顶部或底部的洗牌效果不佳。

使用 ORDER BY RAND() 进行洗牌是一种合理的方法,但有一些事情需要注意:

  • 如果 RAND() 生成两个完全相等的随机数,则会引入轻微的偏差,因为它不会正确地对这两张牌进行洗牌彼此。
  • RAND() 在加密上不安全。通过查看这副牌中的一些第一张牌,熟练的攻击者可能会推断出用于洗牌的 PRNG 的内部状态,从而预测剩余的牌。
  • ORDER BY RAND() 需要 O(n log(n)) 操作。它很可能在混排 52 行时具有可接受的性能,但例如,您可能不希望将其用于混排数百万行。

出于娱乐目的,您的方法应该没问题。如果这是为了大笔资金,您可能需要使用更好的随机播放算法,例如 Fisher Yates shuffle 和加密安全随机数生成器。

Shuffling with real cards isn't really all that random unless you practise it a lot. It's easy to shuffle incorrectly so that either the top or the bottom of the pack isn't shuffled well.

Using ORDER BY RAND() to shuffle is a reasonable approach but there are some things to be aware of:

  • A slight bias is introduced if two exactly equal random numbers are generated by RAND() as it will not shuffle those two cards correctly with respect to each other.
  • RAND() is not cryptographically secure. By seeing some of the first cards in the deck it might be possible for a skilled attacker to deduce the internal state of the PRNG used to shuffle the deck and therefore predict the remaining cards.
  • ORDER BY RAND() requires O(n log(n)) operations. It will most likely have acceptable performance for shuffling 52 rows, but it is probably not something you want to use for shuffling millions of rows, for example.

For entertainment purposes your approach should be fine. If this is for serious money you might want to use a better shuffle algorithm such as the Fisher Yates shuffle and cryptographically secure random number generator.

唠甜嗑 2024-10-25 14:46:53

供您使用:可能。

从博彩业的角度来看:不会。

内华达州博彩委员会负责监督这里批准的游戏的赔率和随机性。出于这样的目的,消除 RE 随机发生器的可能性符合赌场的利益,因此真正的游戏软件使用过期的“真正的随机”种子,这些种子必须通过经过认证的方法(通常使用一些自然混沌输入)获得。银行经常会使用类似的工具。

如需进一步阅读,请参阅 LavaRand

http://www.lavarand.com/

For your use: Probably.

From the gaming industry perspective: No.

The Nevada Gaming Commission oversees the odds and randomness of approved games here. For such a purpose, it is in the interest of the house to eliminate the possibility of RE the randomizer so the real gaming software uses expiring "true random" seeds which must be obtained by certified methods (usually using some naturally chaotic input). Banks will often employ similar tools.

For further reading, see LavaRand

http://www.lavarand.com/

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