Using Random Rule and Sampling Rule Steps
- Updated on 09 May 2013
- 3 minutes to read
The Random Rule and Sampling Rule components provide a way to test for probability with in a flow. Within certain boundaries both components will randomly return one of two outcomes "True" or "False." The random outcomes can be weighted by configuring the percentage of times that the outcome will be true. To guarantee the ratio of "True" to "False" outcomes, the Sampling Rule offers an additional option for configuring the sample size. The Random Rule and Sampling Rule components can be found in the Flow Designer Steps panel, under the category Data > Rules .
Our example flow will choose to follow one of three paths. About 50% of the time it will follow the path to send a Customer Satisfaction survey. If our flow does not follow the path to send a Customer Satisfaction survey, it will choose to either send a thank you email, or send an email containing a coupon.
The sample size for this second choice is 10. This means that if our flow chooses to follow the path to send a thank you email containing a coupon five times, it will not choose that path again until it has chosen both paths a total of 10 times. The same holds true with the options reversed.
It's easier to visualize how probabilities work in practice. Here is the flow that contains the random and sampling rule components:
The three paths described earlier will send either a customer satisfaction survey, a thank you email, or a thank you email containing a coupon.
TheRandom Rule component determines whether our flow will send the survey or emails, which is the first probability. It can be found in the Steps panel, under the heading Data > Rules .
The Sampling Rule component test whether our flow will send an email with a coupon. It can be found in theSteps panel under the category Data > Rules .
For the paths, connectRandom Rule's "True" outcome to the path that sends the survey, and the "False" outcome to Sampling Rule . The Sampling Rule's "True" outcome will be mapped to the path that sends the plain thank you email, and its "False" outcome will be mapped to the path that sends a thank you email containing a coupon.
Next, configure Random Rule 1 to choose the "True" outcome 50% of the time. Click on this step, and go to the Properties panel, under the section Inputs > PercentTrue .
Because PercentTrue is an input, we could dynamically determine the probability of a truthful outcome by giving it a dynamic mapping. We only need our outcome to be truthful 50% of the time, all the time, so we will give this input the Mapping type Constant and a Value of "50."
Next, configureSampling Rule . Just like Random Rule , Sampling Rule should return a truthful outcome 50% of the time, so map its input to a Constant and a Value of "50."
We also want to guarantee that 50% of the outcomes will be truthful when Sampling Rule is tested 10 times. This can be configured under the section Inputs > sampleKey . We want our sample size to be a constant value of 10, so give sampleKey a Mapping type of Constant , and a Value of "10."
This completes our flow. It's now ready to be saved and tested.
In our first debugger session, Random Rule returned the outcome "False," and therefore the customer satisfaction survey was not sent.
In our second debugger session, Random Rule returned the outcome "True," which directed our flow to Sampling Rule. Sampling Rule returned the outcome "True," therefore a thank you email was sent.
For the next ten times that Random Rule has a truthful outcome, Sampling Rule will be given the option to randomly return either a "True" or "False" outcome. By the tenth time, however, it will have chosen both outcomes exactly five times.