随机数生成:从均匀分布到正态分布的探索
1. 扑克牌分发示例
在编程中,我们常常会遇到需要模拟随机事件的情况,扑克牌分发就是一个很好的例子。以下是相关代码:
// Definition of init_deck() to initialize a deck to a full set of 52 cards here...
// Definition of deal() that deals a complete deck here...
// Definition of sort_hands() to sort cards in hands here...
// Definition of show_hands to output all hands here...
int main()
{
// Create the deck
Deck deck;
init_deck(deck);
// Create and deal the hands
Hands hands(4);
deal(hands, deck);
// Sort and show the hands
sort_hands(hands);
show_hands(hands);
}
执行这段代码后,可能会得到如下手牌展示:
3C 9C 10C QC AC 2D 3D 9D QD 2H 6H JS QS
2C 4C 6D 8D JD KD 3H 8H 9H KH 9S 10S KS
5C 6C 8C 5D AD 5H 1
超级会员免费看
订阅专栏 解锁全文
2359

被折叠的 条评论
为什么被折叠?



