Data Generation Scripts

This topic presents a variety of CloudTest data generation scripts. Scripts can be copied and pasted directly into the CloudTest Script Editor using Central > Scripts. Longer scripts have an accompanying image that can be clicked to pop out the full example s ript. Shorter scripts are presented inline (in the right column).
  1. Script 1: Random number/string generator

The Random number/string generator script will generate a random number and place it into a test clip.


  1. The function to the right generates a random integer (whole number) contained within the two extremes (inclusive on lower extreme, exclusive on upper).

function generateRandomNumber(lowerExtreme, upperExtreme) { return Math.floor(Math.random() * (upperExtreme - lowerExtreme) + lowerExtreme); }
For example, generate a random number, either 1, 2, or 3: var num = "" + generateRandomNumber(1,4);
Generate a random number either 5, 6 or 7: var num = "" + generateRandomNumber(5,8);
Generate a random string of the given length using alpha- numerics (upper and lower case). var ranString = generateRandomString(5);
The next example generates a random string of five characters in length, such as: "udG6Z" function generateRandomString(stringLength) { var pool = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var poolLength = pool.length; var randomString = []; for (var ndx = 0; ndx < stringLength; ndx++) { randomString[randomString.length] = pool.charAt(generateRandomNumber(0, poolLength)); } return randomString.join(""); }
  1. Script 2: Generate a random number of 7 or 8 digits

The Random number/string generator with seven-eight characters script will generate a random number with seven or eight characters and place it into a test clip.


Lines 1-3 create a function to generate a random number. function generateRandomNumber(lowerExtreme, upperExtreme) { return Math.floor(Math.random() * (upperExtreme - lowerExtreme) + lowerExtreme); }
Line 5 creates a variable, num, to store the random number, which will contain seven to eight characters. var num = "" + generateRandomNumber(1000000,99999999);
Lines 7-8 place the random number into the current test clip context as a property. $context.result.postMessage($context.result.LEVEL_INFO, "Random rUID: " + num); $prop.set("MessageClip", "rUID", num);
  1. Script 3: Using properties to generate unique data

This simple script uses properties to generate unique data:
{%%Sys-Prop:Composition:StartTimeMillis%%}-{%%Sys-Prop:Track:VUNumber%%}-{%% expr: $context.currentClipIndex %%}
  1. Script 4: : Generate guaranteed unique numbers based on a timestamp

This simple script guarantees unique number generation based on a timestamp:
var vus = new Number($context.currentTrack.systemPropertyList.getPropertyValue("VUNumber")); var startTimeMilis = new Date().getTime(); var clipIndex = $context.currentClipIndex; if(-1 == clipIndex) { clipIndex = 0; } var uniqueNumber = vus+"-"+startTimeMilis+"-"+clipIndex; //var uniqueNumber = "0"; $context.result.postMessage($context.result.LEVEL_INFO, "uniqueNumber = "+uniqueNumber); $prop.set("MessageClip", "userNum", uniqueNumber);