Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I would contest that the OP was doing their best to communicate their desired results, and that Inferring that this was for a game, given this is the game design community, I gave a more contextualized answer that is now a complete methodology to achieve said required results. OP can make it look exactly as they wish using my approach. The assumption of an algorithm could be seen as potentially erroneous. Not trying to be combative, just trying to fully respond to your input.