Factor out sample pattern generation