Pick a card, any card
Pick a card, any card is a web service that lets you simulate drawing a specified number of playing cards from a specified number of decks. It is best thought of as a demo or proof-of-concept, but feel free to use it if you want, as long as you're not overtaxing this server.
(Note that the code that displays the rectangular card layouts above is part of this page, not part of the service. Paste the example URL above into your browser's address bar to see exactly what kind of output you'll get.)
Parameters
Call the script using these parameters:
- num_cards
- A positive integer indicating how many cards to draw. Default is 1; upper limit is 500.
- num_decks
- A positive integer indicating how many decks to shuffle together. Default is 1; upper limit is 500. Or, this can be the string inf, meaning an infinite number of decks.
- game
- Either poker (the default) or pinochle.
- num_jokers
- A positive integer indicating how many jokers to include in each deck. Note that the total number of jokers is the value of num_jokers times the value of num_decks. Default is 0; upper limit is 500. (Most decks contain either 0 or 2 jokers. I have no idea why you'd want 500, but follow your heart.)
- format
- What format you want the response in. Default is text; other options are longtext, json, and xml.
About
The randomizer is Perl's List::Util; I'm not sure exactly what randomizer that uses, but it looks like regular old srand() or something like it. You shouldn't run a casino off this service (and not just for that reason), but it ought to be fine for recreational purposes.
I learned about Moose at the DC-Baltimore Perl Workshop 2013. I went home and started writing something with it, and this is what it turned into. Moose makes writing object-oriented Perl a lot less painful.
Download
You'll need to install Moose and Moose::Util::TypeConstraints (cpanm Moose). The other dependencies are part of the Perl core.
- Card.pm - module that defines the "Card" object.
- Deck.pm - module that defines the "Deck" object. Requires Card.pm.
- any-card.cgi - CGI script that chooses and serves cards. Requires Deck.pm.