#Go 言語でシャッフルした52枚のトランプを1枚ずつ配るサンプル ( Go lang deal shuffle playing cards example )

```golang
package main

import (
	"fmt"
	"math/rand"
	"time"
)

func main() {
	cards := generateCards()

	shuffleCards(cards)

	yourCards := []string{}

	for _, card := range cards {
		yourCards = append(yourCards, card)
		fmt.Println("Your cards are ...")
		fmt.Println(yourCards)
	}
}

func generateCards() []string {
	cardSeeds := []string{"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}
	cards := []string{}

	for i := 0; i < 4; i++ {
		cards = append(cards, cardSeeds...)
	}
	return cards
}

func shuffleCards(cards []string) {
	rand.Seed(time.Now().UnixNano())
	rand.Shuffle(len(cards), func(i, j int) { cards[i], cards[j] = cards[j], cards[i] })
}


```


result example

```
Your cards are ...
[5]
Your cards are ...
[5 3]
Your cards are ...
[5 3 8]
Your cards are ...
[5 3 8 J]
Your cards are ...
[5 3 8 J Q]
Your cards are ...
[5 3 8 J Q 9]
Your cards are ...
[5 3 8 J Q 9 9]
Your cards are ...
[5 3 8 J Q 9 9 6]
Your cards are ...
[5 3 8 J Q 9 9 6 5]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10 J]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10 J 6]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10 J 6 K]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10 J 6 K 8]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10 J 6 K 8 2]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10 J 6 K 8 2 Q]
Your cards are ...
[5 3 8 J Q 9 9 6 5 4 4 8 3 7 Q A 4 9 9 7 2 A A 10 5 6 K 2 A Q 4 J 3 5 10 2 8 7 J 10 7 K K 6 10 J 6 K 8 2 Q 3]

```

# Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/3030








<!-- Update From Qiita API -->

# チャットメンバー募集


何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ





# Twitter


https://twitter.com/YumaInaura


<!-- Update From Qiita API -->