Use a common function for each method.

`function generate(pattern)`