Return to site

Playing cards deck online

broken image

For the purpose of the example, I wrote the code in PHP and Angular, but the concepts are applicable to any programming language. In our case, we’re going to be working backwards, starting by building a deterministic and only later incorporating more secure principles. You can see an online demo of the system on my website, RandomDeck

broken image

Those constraints would all be relatively standards if you want to generate a random deck for an online game for example, and the principles can be adapted for any kind of deck, wether it’s a standard 52 cards deck or your Magic the Gathering cards.

broken image

Therefore, it has to be deterministic, since we get a single card at a time, querying a second card, should take it from the same deck as the first.For that reason, it has to be asynchronous, a user requests a single card at a time, not the whole deck,.

broken image

Each time a deck is dealt, it is a new combination that has, most likely, never been seen before by anyone on Earth.įor one of my personal projects I had to generate a deck of 52 cards in a random order, with the following constraints: There is a total of 52!, or 8e68 (an 8 with 68 zeros behind), unique possible ways of shuffling a deck of standard playing cards.

broken image