Configure the Sequential Number Generator Function
This task describes how to configure the sequential number generator function.
Prerequisite: Select the function
 In the Data Model Editor, expand a rule.

Click inside the function field (fx) of a response column and select Sequential number generator. If the function row is not displayed, from the View Options menu, select Functions.
Note: Dynamic data functions are available for lowest level headers only. Complex headers that include lower level headers under them are displayed in italic text (header). To display lower level headers, doubleclick the column header.
Configure the function
In each cell under this function, enter a value in the following format:
Offset;Increment;FormatString
where:

Offset is an integer. Used as the starting point for generating the output of the sequential number generator.
Note: To generate a sequence of numbers that differs for each request/response, each cell with this generator function has an internal numerical counter. When the simulation starts, this counter is always set to 0. Each time a generator function is called, the output value is determined based on the offset and counter. After the output is determined, the value of the counter is increased by the value of the increment, or decreased if the increment is a negative number.
 Increment is a positive or negative integer. Indicates the change to make from one number in the sequence to the next.

FormatString defines the format of the output of the sequential number generator.
The format string includes:
 a regular text string
 (optional) one or more special sequences to define the format of the numerical output of the generator
To determine the output of the number generator, Service Virtualization goes through the format string and constructs an output string using specific rules, explained below.
Format special sequences
Special sequences enable you define the format of the numerical output of the function.
You construct special sequences as follows:
 Each special sequence must start and end with the '#' character.

Each special sequence must contain one or more ‘D’ characters. These characters act like a digit wildcard for a number that will be generated by this generator function. The number will always occupy exactly the number of specified digits. If the number does not occupy all digits, zeros are added before it so that it does.
Example:
 If the special sequence is #DDDD#
 and the number generated by the function is 568
 the output is 0568.

A special sequence may also contain 'd' characters. These characters act as placeholders. If the output of the generator function requires this space, then it will hold a number. If the generated number does not occupy all digits, then the extra spaces are left empty, and not populated with zeros. 'd' characters may only be placed before 'D' characters.
Example:
 If the special sequence is #ddDDD#
 and the number generated by the function is 9857
 the output is 9857.
For the number 125:
 the sequence #DDDDD# outputs 00125
 the sequence #ddDDD# outputs 125
 and the sequence ##dDDDD outputs 0125.

You can construct a format string with multiple special sequences.
Example: You can enter a special sequence to resemble a credit card number format:
 if the special sequence is #DDDD##DDDD##DDDD##DDDD#
 and the number generated is 1234567812345678
 the output is 1234567812345678
Service Virtualization defines the output of the generator according to the following additional guidelines:
 If the number is greater than the maximal number that can be stored within the digits, it is truncated so that it fits within (e.g. if the number was 3456 and the special sequence was #DDD#, the output will be 456).
 If the number is negative, it is truncated the same way as above. Then an additional offset is applied. The value of this offset is based on the number of digits and is selected so that 1 becomes the biggest number that fits within these digits. For example, if the special sequence was #DDDDD#, 1 becomes 99999. If it was #DD#, 67813 becomes 13 which then becomes 87.
 For each empty special sequence (when there are two ‘#’ characters next to each other), a single ‘#’ character is inserted into the output string.
 The numerical output of the generator will be a number that has exactly as many digits as there are 'D' characters in all of the special sequences in the field combined.
 Any characters that are not part of a special sequence are copied to the output string.
Examples
The typical use case is generating strings that make use of an increasing number sequence.
Example: Your input, typed in the cell under the sequential number generator function:
0;1;Visitor###DDD#
will produce the sequence Visitor#000, Visitor#001, Visitor#002...
In cases where remaining time or another resource that is being depleted may identify some object, the decreasing sequences are used to generate such identifiers.
Example: The real service may be generating identifiers based on time remaining until some event starts.
Your input, typed into cell under the sequential number generator function:
10000;100;SnapshotTimeTMinus:#DDDDD#
This cell produces the output sequence: SnapshotTimeTMinus:10000, SnapshotTimeTMinus:09900, SnapshotTimeTMinus:09800, etc.
When generating several classes of identifiers for various products, you want to maintain an independent sequence of identifiers for each class. You can achieve that by creating a separate rule for each class and use just one row in every rule. Use the Is function in the request to distinguish classes from each other. Each rule has a separate counter for the sequential number generator function, so that the sequences are independent.
Example: The 3 product lines have to have easily distinguishable ids. Class 1 has the „1“ set as the first digit, class 2 has 2 etc.
Rule 1, Row 1, your input typed in the cell: 100000;1;codeNR#DDDDDD#
Rule 2, Row 1, your input typed in the cell: 200000;1; codeNR#DDDDDD#
Rule 3, Row 1, your input typed in the cell: 300000;1; codeNR#DDDDDD#
If the service requests IDs in the following sequence {1,2,2,1,3,2,3,1}, the output results are as follows:
codeNR100000, codeNR200000, codeNR200001, codeNR100001, codeNR300000, codeNR200002, codeNR300001, codeNR100002
Consider following the previous use case with just one rule containing all rows instead of separate rules. In such a case, the internal counter is shared. Therefore, the sequences are not independent and the output relies on the previous sequence of calls even though they were not triggering the current row.
Example:
Rule 1,Row 1,your input typed in the cell: 10;10;X1#DDD#
Rule 1,Row 2, your input typed in the cell: 100;100;X2#DDD#
If we invoke the virtual service hitting the Row1, Row2, Row1, the output is „X1010; X2110; X1120“
If the two rows were in separate rules, the output would be: „X1010; X2100; X1020“
It is possible to split the number that is being computed by SNG into multiple parts in the output string. This is achieved by repeating the #DDD# sequence. Note that the 'Ds' sequences within a single row may differ in length.
Example: A cell with the following format, such as a credit card number format:
1234567890123456;1;#DDDD##DDDD##DDDD##DDDD#
produces the following output sequence:
1234567890123456
1234567890123457
1234567890123458
1234567890123459
Data Model Value  Description  Output 

1;1;#ddddd#  Begin with 1 and increment by 1, without any preceding zeros  1,2,3,4, … 
100;1;#DDDDD#  Begin with 100, increment by 1, and use preceding zeros  00100,00101,00102,… 
0;10;ITEM#DDDD#  Begin with 0, increment in multiples of 10 with preceding zeros and a prefix.  ITEM0000,ITEM0010,ITEM0020,… 
See also: