09-21-2012 07:34 AM
Requirement : -
> I want to generate a random number from set of 1-9 numbers .is there any way in cpo ?
Thanks
Siva
09-21-2012 07:37 AM
Yes, write a VBScript function to do such. (using the Execute Windows Script activity)
Here is the one I use:
Set arrArgs = WScript.Arguments
min = arrArgs.Item(0)
max = arrArgs.Item(1)
Randomize
Wscript.Echo INT((max-min+1)*Rnd+min)
Feed it two inputs, Min and Max as variables. Then the output of the script is the random number.
-shaun
09-21-2012 12:37 PM
I created a process that uses 3 steps, all of which happen inside the engine rather than having to span out to a script, so it runs a lot faster.
Technically, it's pseudo-random...
Predefine Output Variable "Random Number" as type "Numeric"
Step 1: Format Date
Format string: fffffff
(that's seven lower-case letters "f")
Original date: [Process.Start Time]
Step 2: Format Date
Format string: ff\0\0\0\0\0
Original date: [Process Start Time]
Step 3: Set Variable
Variable to update: [Process.Variables.Output.Random Number]
New value: ([Workflow.Format Date.Formatted Date]-[Workflow.Format Date (2).Formatted Date])/100000
This returns a basically random number between 0 and 1 (so you can mulitply it by your maximum value) based on the numeric fraction of a second of the start time of the process.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide