shuffle_deck {mmcards} | R Documentation |
Shuffle a Deck of Cards
Description
This function shuffles a deck of cards and returns the shuffled deck. The function can handle standard decks, anonymous decks, and interleaved decks. For interleaved decks, an option to pair shuffle is also available.
Usage
shuffle_deck(
deck_of_cards = function(x) {
standard_deck()
},
seed = NULL,
paired = FALSE
)
Arguments
deck_of_cards |
An anonymous function that returns a deck of cards as
either a data frame or a list of two numeric vectors for interleaved decks.
Default is |
seed |
An optional seed for reproducibility. Default is NULL. |
paired |
Logical flag to indicate if the interleaved deck should be pair shuffled. Default is FALSE. |
Value
A data frame representing the shuffled deck of cards. The data frame
inherits various classes based on its type. All shuffled decks will have the
classes "ShuffledDeck" and "data.frame". Additional class inheritance depends
on the deck_of_cards
parameter:
"StandardDeck" if
deck_of_cards
returns a standard deck (default)"AnonymousDeck" if
deck_of_cards
returns a single vector"InterleavedDeck" if
deck_of_cards
returns a list of two vectors. If thepaired
parameter is set to TRUE, an interleaved deck will also inherit the class "PairedDeck".
Examples
# Standard deck
std_deck <- shuffle_deck()
head(std_deck)
# Anonymous deck
anon_deck <- shuffle_deck(deck_of_cards = function(x){runif(52, 1, 10)})
head(anon_deck)
# Interleaved deck
interleaved_deck <- shuffle_deck(
deck_of_cards = function(x){list(runif(26, 1, 5),
runif(26, 6, 10))})
head(interleaved_deck)
# Paired interleaved deck
paired_deck <- shuffle_deck(
deck_of_cards = function(x){list(runif(26, 1, 5),
runif(26, 6, 10))},
paired = TRUE)
head(paired_deck)