Calculating the value of a single lottery ticket

Here’s a neat question - how much is a lottery ticket worth before the numbers are drawn?

The problem is a fun one for someone with a love of statistics, or someone who just wants to prove a point about why they never buy a lottery ticket. To answer it, I first make a few assumptions.

  1. The value of a future dollar is uncertain, so I will only base the value of winning a jackpot on the cash payment option, and not the annuity payments.
  2. Any prize over $5000 will automatically be taxed at a rate of 25% to federal and possibly some additional amount to state and local depending on the winner’s location. Hence, a jackpot-winning ticket is only worth some proportion of the cash payment option after taxes.
  3. The more tickets that are purchased, the more likely it is that the jackpot will be shared if won, and so the number of tickets purchased must be a factor in any value equation.
  4. The non-jackpot prizes, since they cannot be shared and do not increase from drawing to drawing, will reduce to a simple constant in terms of the theoretical value of a ticket. (not actually true in California for some reason)

To calculate the constant value of the non-jackpot prizes, I can use the odds and prizes printed right on the website of the lottery commission and add the resultant values of each together. For instance, a 1 in 50 chance of winning two dollars confers a pre-drawing value of 4 cents onto a random ticket.

The math is complicated, so I won’t post it all here, but if you’re interested you can read about it over at my personal blog.

Since the calculator involves knowing the number of tickets in play, I’ve worked out a formula for guesstimating the number of tickets sold for a Mega Millions or a Powerball drawing based on the going jackpot. To see it in action, fill in the cash prize amount and then click the appropriate setup link (or leave it blank and the current numbers will fill in for you automatically). I derived the formula using Excel’s trendline function. I’m actually pretty happy with my result. The R-squared value on what turned out to be a classic-looking quadratic was .9955 for Mega Millions and .9875 for Powerball, easily enough for our purposes.

To quickly populate the settings for one of the two big US multi-state drawings, click one of the options below:
Set form for Mega Millions
Set form for Powerball

Jackpot Cash (not annuity) Value: $ million
State and Local Taxes:
(federal taxes automatically fixed at 25%)
%
Number of Tickets in Play: million
Jackpot Odds of Winning: 1: million
Other Prizes, Odds

Hypothetical value of 1 random lottery ticket:

April 02 2008 | ajax | 1 Comment »

Harrisonburg Blogs

Harrisonburg Blogs represents my first attempt at running a Wordpress MU site. The intention is to create a portal where anyone living in or around my home city of Harrisonburg can enter into the blogging scene and easily connect with other bloggers who are already active. To that end, it will serve both as a blogging platform as well as a blog feed aggregator. The idea isn’t really original, and I freely admit that it’s mostly inspired (”stolen” being such an ugly word) by my experience with a website called chattablogs, which a friend of mine from college put together.

The fun thing about this is that I can get lots of ideas for new development tasks in order to take Wordpress way beyond it’s typical capabilities. So far I’ve added in local news feeds, links to the most recent posts and comments sitewide, an ajax-based online poll, and I’ve developed a few new plugins to work both on the home page as well as the various hosted blogs. I’ve also been researching plugins written by others that I can tie in as well. So far my favorite is one called “Weather Icon,” which I use to show the current weather conditions in Harrisonburg.

What I most need now, in order to continue developing it further, are a few alpha testers who can help me find any bugs, suggest and test themes and plugins, and help turn my lone-wolf project into a true community effort. Chattablogs has become a treasure to the now-vibrant blogging scene in Chattanooga, and I’d just love to see the same thing happen here in my new hometown.

By the way, if you live in Harrisonburg, have some familiarity with Wordpress, and would like to be an alpha tester, visit this page.

April 01 2008 | Schmategories | No Comments »

Zend Certified

Well, as of today I am officially certified by Zend as an expert in PHP 5. Around the beginning of the month I purchased the Zend examination bundle. It included both the physical and electronic versions of the study guide by php|architect, 10 practice exams, and the official certification exam, which I finally took today.

At the time, I assumed I would want plenty of time to study, since the test was rather expensive and I would’ve hated to waste my money. As it turned out, based on the results of the first practice test, I was probably ready to pass without any help from the study pack. That feeling was reaffirmed today when I finished the 90-minute timed test in about 45 minutes.

Still, I enjoyed learning a few additional features of the language that I hadn’t encountered before, such as tidy, the SPL, and some of the PHP 5 database interaction tools. I feel I’m probably a better PHP developer now for having gone through the certification study than I was before.

[Update: 4-11-08] Today I received my official certificate in the mail from Zend. Looks like it was actually signed by Zeev and Andi, though with the high quality of today’s printers, I have no way to know for sure. Still, it looks nice. And as pieces of paper for hanging on my office wall go, this one’s a lot cheaper than that one I got from college. There was also a letter with instructions for doing this:
PHP 5 ZCE logo

Cool, huh? It’ll be interesting to see whether having it actually makes my job search any easier. I hope so. Right now I’m doing the solo gig with multiple different clients who each send me a few hours’ work each week. Not bad work all things considered, but not the full-time position I’m still seeking.

March 31 2008 | worth mentioning | No Comments »

Military Signatures

I loved this latest project. It all started when I helped a fellow named Jay on experts-exchange with an issue that had been challenging him for quite some time. After he had his solution, he actually contacted me through a post on this blog asking me to give him a call. I did so, and thus began our partnership.

sigsample4.png

Jay had gotten this idea of putting together customized signature logos for military men and women, where they could display their name, rank, badges, ribbons, and other stats about themselves inside a cool stylized image. But while he’s an impressive graphic artist and has an excellent sense of proportion and design within his signatures, he needed more help with the behind-the-scenes coding than simply posting on experts-exchange could afford him.
sigsample5.png
Anyway, Jay agreed to match my normal hourly rate of pay, and I in turn did my best to not only give him code that did what he asked for, but code which could be easily understood by him, extended, and reused without his having to know too much about the underlying algorithms I employed.

Among the things I did for him, I:

    sigsample2.png

  • gave him a way to define blocks of space within a signature for badges and for ribbons
  • constructed a CMS for adding his images and a simple API for calling them back out
  • turned his forms into database-driven affairs that would write large portions of themselves based on the art residing in the database
  • built a system for saving a member’s selections on the signature-building form and then auto-populating the fields each time the member returned
  • developed a way of adding attachments to ribbons (these can be like a set of stars that denote a particular award has been won multiple times) that even allows users to see an instant preview of their ribbon before building the signature
  • built a queue implementation that prevents server memory overload by making sure only one signature gets built at a time (GD operations are fairly memory intense, and too many at once can cause the server to grind to a halt)
  • created a javascript that sends the form selections back to the server and initiates the image creation without forcing a page reload

sigsample3.pngI’m very pleased to see that Jay’s idea has really started to explode in popularity. And he’s the sort of dedicated individual who will take the tools I’ve given him and constantly be turning out new innovations for his site. His thousands of members love all the work he puts into it, and scores of new signups join every day. His site membership has doubled in just the past 2 weeks. And he still hasn’t spent his first dime on advertising. His traffic is increasing entirely through the viral dissemination of these signatures.

I think they look awesome, and I’m really digging the chance to be part of something that looks like it could be huge.

Check out the site - militarysignatures.com

sigsample1.png

March 14 2008 | php projects and worth mentioning | No Comments »

MasonWolf, Zone Advisor

I’m now a “Zone Advisor” at experts-exchange.com. Altogether, there are 55 of us, each responsible for 1 or more topic areas. In my case, I’m responsible for two: PHP and blogging. The blogging is because of my experience with Wordpress, though it also includes Movable Type, which I have some limited experience with as well. As for PHP, it’s just a really active zone where I have a lot of experience. There’s actually 4 zone advisors who cover PHP (including me), but blogs I’m doing pretty much on my own. Fortunately, the blogging zone isn’t too busy, so I should still be able to do a decent job.

Basically, my responsibility is to try and help anytime there’s a really tricky question, arbitrate if a cleanup volunteer is trying to close a question and it’s not clear whether it’s been answered, and generally just make sure that everyone in my topic areas is following the member agreement (no profanity, cracking tips, abusive language, copyright violation, students trying to get homework help, etc.).

In order to become a Zone Advisor, I first had to prove myself as an expert in my topic areas. Now that I am one, I have the ability to leave admin comments on any question, close any open question, edit any question or comment, and though I’d normally be expected to get one of the site admins to do it if necessary, technically I have the ability to edit or suspend any member’s account. Honestly, I’m not sure why I have that last capability, but whatever.

October 26 2007 | worth mentioning | 1 Comment »

A more general approach to the ISR interview widget

Recently, I developed a Wordpress plugin for the company I work for, Inside Success Productions. It gave Wordpress users the ability to easily add a feed from our website to their blogs, and for our affiliates this meant the chance to earn a small passive income for every new subscriber they sent our way.

Now the problem is, this only works with Wordpress, and there are many other ways of distributing content on the net. So today I created a generalized method to add the same content as the plugin, but which works with any type of webpage. If it can show adsense, it can show our feed. Admittedly, we can’t get SEO benefit from it, since the links are generated with javascript. But just getting out there and being syndicated by our affiliates is still sufficient motivation for doing it. And also, it gave me a chance to apply a little more of my recently acquired AJAX skill (that’s the bit that lets the form tell people how many potential interviews their preferences match).

Play around with it below. Just remember, if you want to earn affiliate commissions, first you’ll have to become a gold member and then fill out our application to become an affiliate.

The preview to the left was created with the following code embedded in my post:

<script src=”http://www.insidesuccessradio.com/tools/ widget_feed.php?output=js&afid=405203&size=1&shows= &cats=&keywords=” type=”text/javascript”></script>

Try it out for yourself by using our script generator:

Enter your ISR affiliate ID:
Select your preferred categories:…or check this box to accept interviews from all categories

Select your preferred shows in the ISR network:…or check this box to accept interviews from all shows

Select your preferred keywords
(or select no keywords to match more interviews)

Keywords or Key Phrases
Select Your preferred display size

(Copy and Paste the following code into any webpage)


October 18 2007 | ajax | No Comments »

My First AJAX project

One of the things which I feel has held back some of my web applications from their true potential has been my lack of javascript knowledge, and AJAX methods especially. I finally decided to do something about this, so I bought a book “AJAX and PHP” from Amazon last week. It arrived this past Friday and I’ve been having a blast learning this technology.

Happily, AJAX isn’t anything technically “new” it’s just a way of using 2 languages that I already have a grasp of. After playing with the examples in the book, I decided to get my feet wet by converting one of my old scripts into AJAX in order to improve its speed.

Basically, this was a component of EdocWizard (mentioned here) which allowed people to select the appropriate subjects for their eDocs. The subjects are all based on what are called BISAC codes, which simply stands for Book Industry Standards And Communications. The official list of codes can be found at the Book Industry Study Group’s website. I have them backed up to my database, and there’s currently just over 3000 different codes recognized. Amazon allows publishers to pick up to 4 subject codes for each eDoc.

These subject codes are broken up into categories, and originally, I simply made the user wait while the entire 3000+ codes were copied from the database into javascript arrays, and then I had functions that could switch out the display to show the appropriate subjects based on the category the user had selected. My intent was to make it fast to switch between categories without forcing a page reload. It worked, but depending on connection speed it could take a long time for the complete page to finish loading. In retrospect, I should’ve simply forced a page refresh.

Anyway, none of that matters now that the tool has been converted to use AJAX. Check it out by using the form below.

October 08 2007 | ajax and php projects | No Comments »

Turning a Wordpress Sidebar Plugin Into a Widget

Converting a Wordpress plugin to a widget doesn’t have to be difficult, but because the official API’s over at wordpress.org are so lacking in detail (the example they provide won’t even work if you cut and paste), many developers can become frustrated with the process.

STEP 1: Using a widget to call a plugin function (no user input)

To begin, assume you have a very simple sidebar plugin that can be called by editing the sidebar theme directly. In your plugin file, there is some function called “nifty_stuff” that outputs some sort of html code to display in the sidebar. In the bad old days of Wordpress, the only way a user could display such a plugin would be to edit their theme and add the line of code provided by the plugin author to some point in their sidebar.php file (or whatever the sidebar’s name happens to be). And in older wordpress versions and themes this is still what a blogger needs to do, so you want to leave your user with that option.

If the plugin function requires no input from the user, then the following code will add it to their widgets menu where they can simply drag and drop it into a simplified representation of their sidebar. Just add this code to the same script that holds the “nifty_stuff” function:

function widget_nifty_stuff_init() {

if(!function_exists(’register_sidebar_widget’)) { return; }
function widget_nifty_stuff($args) {

extract($args);
echo $before_widget . $before_title . $after_title;
nifty_stuff();
echo $after_widget;

}
register_sidebar_widget(’Nifty Stuff’,'widget_nifty_stuff’);

}
add_action(’plugins_loaded’, ‘widget_nifty_stuff_init’);

Going through the code, what’s happening is that we first want to create a wrapper for our widget function.

Without that wrapper, php will attempt to use the function “register_sidebar_widget” before the script containing it has been loaded. Using the ‘plugins_loaded’ action hook to run the init function ensures that everything loads in the right order first.

The lines surrounding the call to nifty_stuff are there because the widget-enabled wordpress themes may use them, and so they must be supported.

The register_sidebar_widget function associates a label for the widget with the actual widget function that will get called if the user adds it to their sidebar. That label is what the user sees in their widgets menu.

Now, that’s all well and good for really simple plugins. But if your widget needs that user input, then keep reading to learn how to add a widget control. continue reading »

September 30 2007 | open-source and technical articles | 1 Comment »

The ISR interview widget for affiliates

In my current full-time job as webmaster for Inside Success Radio, I don’t often get a lot of opportunity to do really cool new programming. However, I had a blast with my latest project, and I was proud enough of it that I’m going to share it here.

Basically, we run an internet talk radio website, and we have members who pay to listen to our exclusive content. Each interview is broken up into 3 segments, with the first segment telling the guest’s story, and then the second segment giving their expert advice (and this is the stuff people are willing to pay for), and a third segment where they offer predictions about developing trends in their fields. Our experts span the gamut from business and finance to parenting and romance. With multiple subtopics, it’s pretty easy to see how content from our site could be a valuable addition to anyone’s weblog.

So anyway, after I happened to mention to my boss that I knew how to write Wordpress widgets, he asked me if we could use a widget to let someone easily add a feed from our site to their own blog, and get some free links back in the process. I said that I could, and after we hammered out the specs, we came up with this pretty little widget.

You can see the result of this effort in my own sidebar there to the left. It includes just a tiny amount of information about the guest, a feed for listening to the first segment of the interview, and then a link inviting people to our VIP page, where by giving us just their name and email address we’ll let them listen to the entire interview for free. In addition, we offer them a free trial membership. After the trial period expires, they can pay each month to continue to get access to our huge library of content as well as all of our new shows that we add every week.

Now, the exciting feature for the blog owner is that the link to the VIP page includes an affiliate id. If a person signs up as a member and starts paying us each month, we pay a 35% commission on every payment. With just a few new users each month, this can quickly become a great passive income source. In addition, the blog owner specifies the keywords and topics relevant to their own visitors, ensuring that the interviews displayed will be ones their traffic is most likely to be interested in. The featured interview changes each day. As a handy guide, the widget control lets the blog owner know how many interviews in the database currently match their preferences. They can narrow or generalize their settings as appropriate.

The exciting feature for Inside Success Radio of course is that we get numerous links back to our site to improve our search engine rankings. We get 1 link back to the insidesuccessradio.com homepage, 1 link to the homepage of the particular radio show being featured, and 2 links back to the guest’s own promotional page. The other cool thing is that if we want to promote one particular guest on a particular day, we can modify the feed on our end such that if the widget’s keyword, category, and radioshow preferences match, then that guest we’re promoting will be sure to show up as the featured interview. This way we can quickly get dozens of backlinks and traffic all at once. Isn’t that a cool idea?

Anyway, if you think you’d like to have it on your own blog, you can either become a member yourself and request an affiliate id, or else feel free to use mine - 405203. (Hey, it never hurts to ask, right?)

Here’s what bloggers see when configuring their feed:
Options for configuring the ISR feed widget

September 27 2007 | open-source and php projects | No Comments »

The Experts-Exchange Badge

Though I originally developed this wordpress plugin just for my personal use, I decided to generalize it so anyone can display their rank on experts-exchange.com. Now I’m hoping others find it useful as well.

The point tally automatically updates when you gain new expert points, so it’s never out of date. As you pass milestones like 50K, 150K, 300K and so on, the graphic will switch to show your current shield of courage. It’s a snap to use either as a direct function call in your sidebar.php file or as a widget. And the badge itself is a link back to your experts-exchange profile.

eebadge screenshot

Click this link to download the plugin.

After unzipping the contents, place them inside your wordpress plugins folder. In the admin panel, go to your Plugins menu and activate the Experts Exchange Badge plugin.

To have it display on your page, go to your Presentation menu and click the “Widgets” option. Drag the widget named “Experts Exchange Badge” into your preferred position in the sidebar. Click on the configuration link and complete the link to your profile in the input window. Now click “save changes”. Your badge will now appear for all your wordpress visitors to see.

As an alternate method, if you don’t want to use widgets you can modify your sidebar.php file directly. Again go to the Presentation menu, this time selecting the “Theme Editor” option. Select the sidebar file you wish to modify (or any other template you want to show your badge) and add the following line:
<?php ee_badge(’[your profile id]‘); ?>
(replace [your profile id] with the code that completes the link to your profile: http://www.experts-exchange.com/M_[your profile id].html)

September 19 2007 | open-source | 1 Comment »

Next »