Based on Gamedev Tuts and @McFunkypants' Random World Generator.
For a roguelike game I'm making in HTML5 I needed to create random maps each time the game started. I came across the cellular automata procedural generation article on Gamedev Tuts and adapted it to create levels from within the game.
I also created a standalone version which creates a JSON tilemap to be used in other projects.
View code on Github.