Skip to content

A lightweight Go package to generate, shuffle, and draw from standard 52-card playing decks.

License

Notifications You must be signed in to change notification settings

notcacti/godeckofcards

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDeckOfCards

A lightweight Go package to generate, shuffle, and draw from standard 52-card playing decks.

Go Version License

✨ Features

  • 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

📦 Installation

Run this command in your shell:

go get github.com/notcacti/godeckofcards

🚀 Usage

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())
	}
}

🧠 API Overview

NewDeck(shuffle bool) Deck

Creates a new 52-card deck. Set shuffle to true to randomize the order.

GenerateDecks(count int, shuffle bool) ([]Deck, error)

Creates multiple decks. Caps at 50 for sanity.

deck.Shuffle()

Shuffles the deck in place.

deck.DrawCard() (Card, error)

Removes and returns one card from the top of the deck.

deck.DrawCards(n int) ([]Card, error)

Removes and returns n cards from the top of the deck.

Card Methods:

  • Code() → shorthand (e.g. "AS")
  • Rank()"A", "2", …, "K"
  • Suit()"S", "H", "C", "D"

🪪 License

MIT © CactiFX

About

A lightweight Go package to generate, shuffle, and draw from standard 52-card playing decks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages