Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

"force" rand() to produce designated number of matching values within range


Dear all,


I tried to find answer on the topic but did not come even close to it, so I kindly ask for help. I have attached a file with a sampe of my data to be easier to explain.  As you can see, the column "in hour" takes the value from the column "hour" each time the randomly produced number from the "rand" column falls within the range of "min" and "max" columns (which are fixed values).

What I try to achieve is to "force" the "rand" column to yield exactly as many values that will fall within the range of "min" and "max" as the value in the "prob Anm" column. For instance the "webinar_id" 645 has two entries that fall within the range, but "webinar_id" 643 should have 1 match, but has none, or "webinar_id" 644 has 1 match but should have 2.

Please note that when in "prob Anm" stays 0, no random number from "rand" should fall in within the range of "min" and "max".

Thank you for your answer!



Hi @jeanilieski,


In order to "force" the number of instance that fall in range, could you to randomize twice? For instance, for webinar_id =643, prob Anm = 1, you could randomly pick one of those rows, then randomly pick a number between that min and max. For the others, you can randomly pick a number outside that min and max. Make sense?





Alteryx Certified Partner
Alteryx Certified Partner

Hi @jeanilieski 


I could have done with 1 batch macro, but I decided to go with 2 iterative macros. It took me a while to get the right mindset.


Please check the workflow and macros and let me know if you have any doubts. I also changed the Input to a .yxdb to be faster.


Package appended.



thank you mmenth.

your thought gave an unexpected twist in my workflow, but for now it works. In case I cannot go until the end, i will come back to you, and in case it works I will soon accept your solution officially


thank you Tabelaus, I will have a look, although I try to follow the answer of mmnth now.