How does it work?

If you would like to download and adapt this website, you can get the source code for the site here.

This website uses Kate Compton's Tracery to generate the fortunes. Tracery uses what are called Context Free Grammars / Replacement Grammars to define sentences using both known text and replacement targets

e.g. "my favourite colour is #colour#" will replace #colour# with an element from the #colour# rule (e.g. "colour": ["red","orange","yellow","green","blue","indigo","violet","#colour#y-#color#"]). The text used to replace the target is chosen randomly. Importantly these targets can be nested, as seen in the colour example above. You could get "my favourite colour is red" or "my favourite colour is orangey-green" or if you're very lucky "my favourite colour is bluey-orangey-red". This happens because #colour# has a 1 in 8 chance of picking #colour#y-#colour# as its value, for which each #colour# is replaced again, potentially even choosing #colour#y-#colour# again!

The site uses a cookie (text file stored locally on your PC) that expires at midnight to keep track of who you are. This cookie stores a number that's randomly generated when you access the site and it can't find the cookie on your PC. This number is used to seed Tracery's random number generator so it generates the same output each time.

To copy to the clipboard, the site makes an invisible text area and copies the HTML from the fortune text into it, replacing <br> tags with \n (the newline character), then executes a copy command on that text area. I had to manually filter down the emoji list to those that are supported by most browsers. This unfortunately means there's a few I either missed or that still aren't supported by certain browsers.

Site and generator source code are CC BY 4.0 licensed. This means that you may freely reuse them, for profit or no, with attribution (please link to and attribute to John Willcox-Beney). This does not extend to the technologies used for either and those licenses may change. Generated prophecies are in the public domain and may be used and shared freely.