Rewritten from scratch rand phrase function