Ziggurat Algorithm - ported to JS by http://www.filosophy.org/labs/