A lightweight Go package to generate, shuffle, and draw from standard 52-card playing decks.
- Create single or multiple 52-card decks
- Shuffle decks with seeded randomness
- Draw one or more cards
- Clean, idiomatic Go API
- Private/internal logic encapsulated
Run this command in your shell:
go get github.com/notcacti/godeckofcards
package main
import (
"fmt"
"github.com/notcacti/godeckofcards"
)
func main() {
// Create a new shuffled deck
deck := godeckofcards.NewDeck(true)
// Draw a single card
card, err := deck.DrawCard()
if err != nil {
panic(err)
}
fmt.Printf("Drew card: %s (%s of %s)\n", card.Code(), card.Rank(), card.Suit())
// Draw 5 more cards
hand, err := deck.DrawCards(5)
if err != nil {
panic(err)
}
fmt.Println("Hand:")
for _, c := range hand {
fmt.Println(" -", c.Code())
}
}Creates a new 52-card deck. Set shuffle to true to randomize the order.
Creates multiple decks. Caps at 50 for sanity.
Shuffles the deck in place.
Removes and returns one card from the top of the deck.
Removes and returns n cards from the top of the deck.
Code()→ shorthand (e.g."AS")Rank()→"A","2", …,"K"Suit()→"S","H","C","D"
MIT © CactiFX