Edit: as pointed out below, the algorithm was lifted from another version done in Python/Matplotlib by Jake Vanderplas: http://jakevdp.github.com/blog/2012/10/07/xkcd-style-plots-i...
http://xkcdsucks.blogspot.com/2009/03/xkcdsucks-is-proud-to-...