Pick a card, any card
Pick a card, any card is a "web service" that lets you draw a specified number of playing cards from a specified number of decks. Feel free to use it 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.)
Call the script using these parameters:
- A positive integer indicating how many cards to draw. Default is 1; upper limit is 500.
- 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.
- Either poker (the default) or pinochle.
- 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.
- What format you want the response in. Default is text; other options are longtext, json, and xml.
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 is great; it makes writing object-oriented Perl a lot less painful.
You'll need to install Moose and Moose::Util::TypeConstraints (cpan install 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.