renamed main() to generate() and returns array