Tag Archives: Python

Python Says The Lottery Should Be Illegal

The House Always Wins

I want ‘free’ money.  Who doesn’t.  Winning multi millions in the lottery after buying 1-2 $2 tickets is a great deal…and easy.  Or so it would seem.  I like that feeling I get after buying a lottery ticket or two.  It’s a feeling of hope.  Man, think of all the things I could do with $100 million dollars!  I could pay off my mortgage, pay for my kids’ college expenses without a second thought of angst, buy a brand new car.  I’d buy a lamborghini huracan too, just because (shoot, right now I don’t even own a car).  Think of the peace of mind you’d have once you had all that money in the bank earning interest.  Financial freedom – the ability to decide how you actually want to spend your time each day, the freedom to travel.  Maybe go sailing whenever and wherever you wanted to.  Unfortunately, however, the lottery is not the ticket for these dreams.  Let me show you.

I have spent a lot of money on lottery tickets.  Powerball, Mega Millions even a scratch off or two.  I’ve never won much money.  There are reasons for that:  Math and the ‘House Always Win’.  As an individual lottery ticket purchaser, you are simply one of many people funding the pot….the house’s pot.  They win, you lose.  Always.  Sure, there are anecdotes of individuals winning the lottery that The House wants to be sure you are aware of, but who are they, really?  Have you ever met one?  Not likely.

I wrote a computer simulation to show just how unlikely it is to win the Mega Millions Jackpot, in particular.  After I ran this simulation a few times, I was pretty well convinced I no longer want to spent any of my money buying tickets.  It really is a mega rip-off.  It’s just that it’s sometimes hard to see how big of a rip-off it actually is when you always think of the potential upside.  The potential upside, however, is almost non-existent.

Here’s the output from my first Jackpot Simulation Run:

House Draws:

10, 13, 50, 53, 64 Mega Ball: 16

Your Tickets

5, 21, 43, 46, 51 Mega Ball: 9

10, 13, 50, 53, 64 Mega Ball: 16

   Winning Amount $100000000

Total Games Played: 16723798

Total Time: 671.52312088 sec

Avg Games Per Sec: 24904.0

Total Money Spent: $66895192

Total Money Won: $105487574

In the simulation above, it took almost 174,206 years of buying 2 Mega Millions tickets, two times a week, for a total of 16,723,798 games played, before actually hitting a Jackpot.  In that time, I spent over $66,895,192.  On the upside, however, I did also gross $105,487,574 in total winnings.  But again, it only took me 174,206 years of trying.

The code for my simulation is in GitHub (https://github.com/jcaple/MegaMillySim).  Give it a run and let me know what you think.  And if you ever hit the Jackpot in a National Lottery, I’ve got a bridge to sell you…

All Your Face Are Belong To Us: DeepLens Challenge Day 5

Keep Hope Alive

This is Day 5 (for me) of the DeepLens Challenge, which I talked about starting in my post here.  I have to submit my project by February 12th or 13th.  I’m making progress toward my project goal, which right now is simply to recognize a face in an image cache from a live video feed using the stock face detection model on the DeepLens device.  Face and image recognition is pretty common place today, I guess, but I’m stoked to get something similar working myself.  I’d also love to integrate Alexa into the mix somehow as well, but I need to start making bigger strides with less messing about with the fiddly things!

Coding Challenges And Solutions

Some of the challenges I’ve faced, and (mostly) overcome, so far include:

  • Cropping a detected face out of the DeepLens video feed in the Lambda Python script.  Turns out this is very simple, but it took me a while to figure out.
  • How to convert the cropped face image to a jpg and write it to disk.  Also very simple in retrospect, but I’m a moron.
  • I thought it would be easy to write the resulting face jpg to AWS S3 from the DeepLens edge device, but this one I just could not figure out due to permission issues.  I can write to S3 using the aws cli as the aws_cam user, but so far I’ve not been able to extend those same permissions to the ggc_user account, which seems is what runs the awscam software.  I even hard-coded credentials in the creation of my S3 client in the lambda code, but still had permission problems.  I had to back-off from hacking on the device out of fear of really screwing something up, however.  Best to stay off the DeepLens as much as possible in retrospect.
  • The only way I was able to get a face image off the DeepLens and into the cloud so far is by converting it to a base64 String, putting into a JSON object, and putting it on the IoT Topic.  I worry that all this data transfer is going to cost me an arm-and-a-leg by the end of this thing…
  • When creating a lambda function to read from the IoT Topic, I kept getting a random error when trying to save it, which made no sense as I was following an AWS Blog Post for how to do the same.  Then I found this: https://forums.aws.amazon.com/thread.jspa?messageID=825417&tstart=0.  And this is what makes hackathons using new technology so fun!  Writing software is really just lots of Google Searches.

And speaking of the Internet of Things (IoT), to-date I’ve thought this was just another marketing buzz word that wasn’t going to pan-out, so to speak.  I used to think the same about ‘cloud’ (and still think this about Bitcoin and its ilk).  But this DeepLens development challenge is giving me a greater appreciation for IoT and edge computing.  In fact, we’ve been talking about the proliferation of internet connected things and the resulting possibilities since Java Jini, and probably before that, but I suspect Python will be its great enabler instead of Java at this point.  But I digress…

Baby Steps, But Machine Learning Learning No Where In Sight

So as of today, I am able to leverage the stock face detection model to detect and crop a face out of a live video feed from DeepLens, send it up to the AWS Cloud Lambda IOT Topic Listener, and put it into an S3 Bucket.  Next step is to try to figure out how to use the AWS Rekognition service to recognize face images in an image cache.

The Flow Zone

I’ve found listening to music particularly distracting these last few days.  However, I find this Horn Solo in Tchaikovsky’s 5th Symphony really soothing and not distracting (but too short).  I played this solo in Solo and Ensemble in High School.  I’ve been told that french horn players are better kissers…

Go Daddy Shared Hosting – They Do It Their Way…

During my drive home from work tonight I thought I might try to see if I could get some simple JSON REST services running on on my Go Daddy Shared Hosting Account.  I’ve never used Sinatra before and wanted to see if I could build something useful with it and have it running on the internet…for realz.  Unfortunately, Go Daddy appears to have discontinued all Ruby Support as of January 2014.  The curious thing, however, is that I have ruby on the command line on my server, and could even install Sinatra (‘gem install sinatra’), but I cannot get the simplest ruby script to run as a CGI script without getting a 500 Server Error.

Conclusion?  I will stick with Perl scripting (currently Go Daddy supports Perl, PHP and Python) for now since I am too cheap to upgrade to a Virtual Private Server (VPS) just for this reason.  However, If I build something substantial and/or mildly popular at some point in my life, I would like to maybe use Sinatra based web services in support of my application.  But by then, I may be using a different hosting service provider so I can do things MY way.