Pages

Monday, November 11, 2013

Auto-Splitting Using Random Number

Among Business Processes, occasions to use random numbers are only few.
If I'm forced to say, they could be cases of changing Reviewers randomly for internal control reason or, cases of 'Choosing winners' in a giveaway campaign or so on.

The following Workflow sample is a Business Process definition to play 'Word chain game' in the company. I have written about it in a blog post on the Questetra Blog, and it is totally practically useless, but a few readers want to see the 'archive', so I decided to present it as a content on this particular website again. (Of course, you can download the archive for free.)

In this example, the contestant of the Word Chain game is chosen by a random number for answering. It generates a random number just before the Splitting Gateway, and the path of the Gateway is chosen according to the random number. (Auto-Splitting)


[Word Chain Game flow]


The 'random number' we use here, is generated each time by Javascript (ECMA) function [random] in the auto-processing, "Script Task". The function [random] generates 'decimal between 0 and 1', so the script truncates the fractional from the doubled value (random()*2) to get a natural number greater than or equal to 0 less than 2.

Math.floor(Math.random() * 2); //floor: Truncation function (floor function)

If you want selection of 5, make it [Math.floor(Math.random() * 5)], if 10 [Math.floor(Math.random() * 10)]. Whenever you need random numbers in the middle of your Workflow, please use this.

* Auto-processing "Script Task": Available in version 9.7 and after of "Questetra BPM Suite", the Cloud-based Workflow.

[Word Chain Game flow:'2a. Answer' screen]

[Property Screen of Script Task]

[List of Process Data Item]


[Download]
<Similar Models>
<<Related Articles>>