MacMost Q&A Forum • View All Forum QuestionsAsk a Question

# How Do I Generate a New Random Number Based On a Certain Condition In Numbers?

Some time ago I decided I wanted to create a semi-smart outfit-picker in Numbers. I am well on my way but now I have stumbled upon the problem that I want to make sure some colors (e.g. Black and Navy) are not combined in this outfit. I am now generating random numbers for each piece of clothing and those create an outfit, however if, for example, the shirt and the pants have the colors black and navy I want to regenerate those random numbers until the colors do fit together. Is there a way to regenerate those random numbers based on a certain condition?
—–
Joris

### Comments: 2 Responses to “How Do I Generate a New Random Number Based On a Certain Condition In Numbers?”

5 years ago

That's tricky. One way to do it is this:
You have one table with shirts, and other table with pants. The first column is the name or identifier for the item. The second column is the color.
In the third table, you would have the first column be a random number. Then the second column matches that with the first table to show the shirt identifier. The third and fourth columns are a random number and the pants that match that number.
The fifth column is a formula that uses IF functions inside an OR to give you a true or false depending on whatever a situation is found. Like if blue pants and black shirt. Any true means it is a bad match.
You have like 100 rows in this third table. Each has random numbers in columns A and C and shirt and pants in B and D. E is the long IF/OR formula. So each row has a true or false in E. The first row with a false is the first one that matches your conditions.
So then you can filter that row to only show where E is false. Then the first one is your answer. Or have a fourth table that shows one row with the shirt and pants from the first row in table 3 where it matches false.

Joris
5 years ago

Thanks a lot! I was really well on the way and I think this is just what I need to make it work like I wanted it to. I don’t have the types of clothing all in different tables but I have them in the same table with custom ranges the random number can generate (e.g. From first to last occurence of type “pants”). I think this should work the same as your proposal though.