Showing results for 
Search instead for 
Did you mean: 
Walkthrough Wednesdays

Selecting a random wav file to play in CVP app

This document was generated from CDN thread

Created by: DAVID CHUMBLEY on 05-12-2008 02:37:07 PM
I have 5 wav files that need to play randomly to callers in queue. I'm trying to determine what the easiest way to accomplish this within my CVP app. In IPIVR, there was a Random Prompt generator. With CVP I think I need to build a java class that will randomly determine the order of the wave files to play. Is that correct? I'm looking for ideas on the best way to accomplish this. Thanks

Subject: Re: Selecting a random wav file to play in CVP app
Replied by: Janine Graves on 05-12-2008 02:53:36 PM
When calls are in a queue, it's usually ICM that instructs the voice
gateway which audio to play (using the Play Media microapp ). You don't
usually send calls into the CVP Studio app to just hear an audio when
calls are in queue. So I'd say that you should find a way to do this
within the ICM script.

If you did decide to send them into CVP Studio app for this, then yes,
you'd have to write some Java code to do the random number generation
and then use the result to select an audio file.

Subject: Re: Selecting a random wav file to play in CVP app
Replied by: GEOFFREY THOMPSON on 05-12-2008 08:51:57 PM
Janine is correct. I do this a lot with microapps, but have not found a way to start with a random selection. This is fairly straightforward.

I have 8 "marketing messages" that I play in sequence with a special type of play media microapp, interspersed with an "all agents are busy" play media microapp of the normal form.

You just set up a counter, convert it to text, append it to a string like "qmessage_" and append ".wav".

Now set a peripheral variable (say PV8) to this "qmessage_1.wav" and use the special Play Media microapp with the name "PM,-8" which you can look up in the Guide: it gets the name of the wave file from peripheral variable 8.

This is a pretty handy microapp form - you can think of other uses.

Now you just need a loop, a check on whether you've hit the max, and a reset. This can all be done with ICM "sets" and "ifs" though it is a little tricky and I bet you don't get it right first try. if you do, I owe you a sixpack. ;-)

If you can figure out how to make ICM generate a random integer between 1 and 8, I'm all ears.


Hi Geoff,

How do you create a counter in ICM Script to add the queue message number with the prefix "message_" and suffix ".wav"?

Thank you!

Rising star

You can generate a random number in ICM (look in a Set Variable node at the Formula Editor's Built In Functions there's a function called random() - which returns a random number ibetween 0 and 1 (eg, 0.12464).

You can then use the substr(originalString,startPosition,numChars) function, to grab the 3rd character  (the one just to the right of the decimal) returned from random() .

Here's the expression:     substr(random(),3,1)

So, to create your audio file names like message_#.wav (where # is between 0 and 9) use:  concatenate("message_",substr(random(),3,1),".wav)

Rising star

If you really wanted to create a 'counter' you just select a variable (like PV10) to use as your 'counter'

Then use these nodes:

1) SetVariable:  assign into PV10 the Value: -1 (no quotes) - this is done once.

Now Loop these 3 nodes forever:

2A) SetVariable: assign into PV10  the Value:  mod(Call.PeripheralVariable10+1,10)   ***NOTE Use mod function to keep the value of PV10 between 0 and 9 - so  files are named message_0.wav through message_9.wav

2B)SetVariable:  assign into PV9 the Value: concatenate("message_",Call.PeripheralVariable10,".wav")

2C) RunExtScript: PM,-9    (play contents of PV9)

Then through  Steps 2A, 2B, 2C again forever until ICM sends the call to the agent.


Hi Janine, thank you very much for your explanation. In the scripting guide, they are saying that mod function takes the n1 value and divide per n2 e.g. mod(n1/n2)

Because in your explanation, the n2 = 10 you are using for a delimit character. I did the test and also works as you told me.

Thank you in advance and for your help!


This is also a nice explanation. But If I have only 4 audios prompts, how can I delimitate the random number to get only number between 0 and 3? I need to use the if node after the random generate a number to see if the number is below <4? If not generate a random number again?

For example:

1.I will use the random expression to generate a random number

2.With a IF node, I will check if the substr(random(),3,1)<=3

3.IF yes, I will concatenate

4.IF not, I will go back to step 1

Is it correct?

I did it and it works, but is it valid to use in a production environment? I have concern to impact the system performance, because almost every call will pass to this validation until we get the substring<=3.

Thank you!

Cisco Employee

For 0-3, just use trunc(random()*4)


I think it works Paul, but can you explain to me what trunc does?

The manual is so poor

Rising star

I'd definitely go with Paul's suggestion: For 0-3, just use


random() returns a number between 0 and 0.999999...

random()*4 returns a number between 0.0 and 3.999999...

trunc(random()*4) returns the whole number portion of the above - so

you'll end up with 0-3

Content for Community-Ad