# How would YOU code a deck of cards then shuffle them?

**URL:** <https://forum.kirupa.com/t/how-would-you-code-a-deck-of-cards-then-shuffle-them/71951>\
**Category:** Uncategorized\
**Created:** [December 1, 2004, 12:08am UTC](https://forum.kirupa.com/t/how-would-you-code-a-deck-of-cards-then-shuffle-them/71951 "2004-12-01T00:08:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elbudster](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@Elbudster](https://forum.kirupa.com/u/Elbudster)\
**Post date:** [December 1, 2004, 12:08am UTC](https://forum.kirupa.com/t/how-would-you-code-a-deck-of-cards-then-shuffle-them/71951/1 "2004-12-01T00:08:15Z")

</div>

I’ve been wondering that the past few days. This is how I thought of doint it…

here is how I would make the deck…

```php

cards = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king", "ace"];
types = ["hearts", "diamonds", "clubs", "spades"];
deck = new Array();

function buildDeck() {
	for (var i=0; i<cards.length; i++) {
		for (var k=0; k<types.length; k++) {
			var curCard = cards* + " of " + types[k];
			deck.push(curCard);
		}
	}
}
buildDeck();

```

And here is how i would shuffle the deck

```php

function shuffleDeck() {
	var cardPos = new Array(52);
	tempDeck = new Array(52);
	var i=0;
	while (i<deck.length) {
		var ind = random(52);
		if (cardPos[ind] == undefined) {
			cardPos[ind] = i;
			tempDeck[ind] = deck*;
			i++;
		}
	}
	deck = tempDeck;
}	
shuffleDeck();

```

Just curious as to how you would all go about doing it 🙂
