Share this page

# Configure the Sequential Number Generator Function

This task describes how to configure the sequential number generator function.

For information about creating a persistent sequence, see Create a Scripted Rule.

In this topic:

## Prerequisite: Select the function

1. In the Data Model Editor, expand a rule.

2. 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, double-click the column header.

Back to top

## 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.

Back to top

## 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 1234-5678-1234-5678

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.

Back to top

## Examples

Click on this thumbnail for a Sequence Generator cheat sheet.

Example: Increasing sequence

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...

Decreasing sequence

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.

Multiple independent sequences

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-, codeNR-200000, codeNR-200001, codeNR-100001, codeNR-300000, codeNR-200002, codeNR-300001, codeNR-100002

Multiple dependent sequences

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 „X1-010; X2-110; X1-120“

If the two rows were in separate rules, the output would be: „X1-010; X2-100; X1-020“

Multiple number occurrences

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:

1234-5678-9012-3456

1234-5678-9012-3457

1234-5678-9012-3458

1234-5678-9012-3459

Back to top

See also:

- Rule Functions

https://admhelp.microfocus.com Service Virtualization 8942
Tips to improve your search results... Service Virtualization Help Center SV Help 5.4-5.4.1 All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version: