Library-ify the pattern generation