VOGO Voice – Knowledge Base

How to Use a Shuffle Function

Estimated reading time: 4 min

In this in-depth tutorial, you will learn how to write a shuffle function and use it to present a random value from a collection without having to use a random function. Implementing this method allows you to skip performing a random function that involves creating a random number and using that to pick a value from the collection. The comprehensive instructions combined with highlighted screenshots will offer the required direction for implementing the shuffle function to create an array of shuffled values from the given collection using a version of the Fisher-Yates shuffle algorithm. The main advantage of this method is that this function will only have a single parameter, the collection, and the employed function will return the shuffled array.


  • VOGO Voice account: https://www.vogovoice.com/
  • Access rights to the Interactions section.
  • Access rights to the Interaction builder platform.

Create a Custom Intent

Make a suitable intent to be invoked in order to execute a shuffle function interaction mapped to it. 

Create an intent titled ‘Thought For the Day’ with suitable sample utterances mapped to it. The sample utterance for this intent would be: “Thought for the day”, “Thought of the day”, and “Todays thought”

To learn about how to create a custom intent, visit Creating Intents 

Steps to create an interaction flow

  1. Log into your VOGO Voice account to be directed to VOGO Voice Management Console (https://account.vogovoice.com)
  2. Navigate to Interactions on the vertical bar displayed on the left-hand side of the Dashboard.
    Dashboard > Interactions

3. Now, click on the Interactions button at the bottom right-hand corner of the screen. Select the ‘Thought For the Day’ intent to be directed onto the Interaction builder platform.

4. In the flow diagram area, you will be able to see the Start and Response components. 
5. Unlink the Start component from the Response card by clicking the delete icon placed in the middle of the chain.

6. Now, drag and drop an Add Variables component onto the flow diagram area and connect it to the Start Component.

7. Now mouse over the top right corner of the Add Variables component. Click on the pencil icon that appears. This will open up its configuration window. 

8. Configure the Add Variables component by adding the key-value pairs as shown in the screenshot below. Follow the subsequent steps to fulfill this configuration.

9. Fill in the first variable name as thoughts and add the following array as the value in the variable thoughts. Then, set the datatype as Array.

“When you know better, you do better.”,
“If you want to be more powerful in life, educate yourself. It’s that simple.”,
“When you talk, you are only repeating something you know. But if you listen, you may learn something new.”,
“Learn as much as you can while you are young, since life becomes too busy later”,
“The capacity to learn is a gift; the ability to learn is a skill; the willingness to learn is a choice.”,
“The more that you read, the more things you will know. The more you learn, the more places you’ll go!”,
“The more you give away the happier you become.”,
“Worry is a misuse of the imagination.”,
“Logic will take you from A to B. Imagination will take you everywhere.”,
“Be yourself, for everybody else is already taken.”

10.  Now add another variable in the Add Variables component by clicking the additional plus button below. This will allow you to add the next variable and its value. 

11. Navigate to the Data tab adjacent to the Components on the top left-hand side of the interaction builder platform. 

12. Click on the Data part and in the search bar type shuffle. From the drop-down that appears, click on the plus button beside the collection, and this will bring up the shuffle function. 

13. Drag and drop the shuffle function in the value field of the recently attached Add Variables component. This will automatically generate the shuffle function in the respective field. Now configure it as shown below.

👍 Note: Here we name the new variable as myThought. Click the plus button that appears under the heading Arguments and add the argument as var.thoughts which is the array that contains the values to be shuffled and set the data type as Path. It is the var.myThought that will have the shuffled array. 

14. Drag and drop a Response component onto the flow and connect it to the configured Add Variables component. Click on the Voice icon on the top right-hand side of the Response component to configure it.

15. Clicking on the voice icon opens a Speak pop-up window with a field titled Say wherein you need to type a suitable welcome message to present the thought of the day along with the requisite template.

Say: Welcome to thought for the day. Today’s thought is {{var.myThought.[0]}} Have a nice day.

👍 Note: Here the welcome message is for presenting the thought of the day, to introduce which we use the template {{var.myThought.[0]}}. Here var.myThought contains the new shuffled array and by means of it we will retrieve the first element from the array using [0] notation. So each time the interaction is invoked, shuffling of the elements in the array takes place and a different thought for the day will assume itself as the first element in the array to be procured and relayed through the Alexa device. 

To add a display message in a display voice-assisted device.

  1. Click on the Computer icon, and type in the field titled Display Message of the Show pop-up window. 
  2. Populate the required fields and click the Save button. 

Title: Thought for the Day
Display Message: “{{var.myThought.[0]}}”

🖍 Note: Ensure to click the Save button to save the interaction flow as and when edits are made.

For further reference on how to populate the additional fields visit https://university.vogovoice.com/kb/guide-response-component/

Testing and Validation 

  1. Click on the Test button next to the Flow Editor button on the interaction builder platform.

2. In the Tests pop-up window that appears, click the + button on its top right-hand corner. 

3. Fill in the Name field of the Test Response window that shows up. In the Conversation section of the Test Response, the Thought for the day intent through which this interaction flow has been initiated will be auto-generated in the User invokes field as shown below. Then, click Save to perform the test.

4. To validate the Test Response, click on the lightning symbol on the left-hand side of the test case. 

5. Run the test thrice and you will get three different responses in return and each time with a different thought. 
🖍Note: As it happens while employing a random function, here also there is a possibility that you might get the same element repeated.

6. Following are the output while performing the test three times.

Test 1

Test 2

Test 3

Congratulations! You have successfully learned how to write and use a shuffle function to return elements from a shuffled array of values in a given collection using a version of the Fisher-Yates shuffle algorithm.

👍 Note: To test the functioning of the interactions on your device you have to deploy the custom skill to facilitate the skill with the new edits. To accomplish this, click on the Deploy button seen at the bottom of the Skill Settings pop-up window.

To know how to deploy a custom skill visit https://university.vogovoice.com/kb/deploying-a-skill/

To learn about Add Variables, click here.

Was this article helpful?
Dislike 0
Previous: Custom Loop
Next: Tutorial for stripping HTML