cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
739
Views
0
Helpful
2
Replies

Is there any way to generate random number in CPO

msivarami3
Level 1
Level 1

Requirement : -

> I want  to generate a random number from set of 1-9 numbers .is there any way in cpo ?

Thanks

Siva

2 Replies 2

Shaun Roberts
Cisco Employee
Cisco Employee

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

--Shaun Roberts
Principal Engineer, CX
shaurobe@cisco.com

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.