String fields

You can use the generator operator to create fixed-length string and ustring fields or string and ustring fields with a specified maximum length; you cannot use the operator to generate variable-length string fields. If the field has a maximum specified length, the length of the string is a random number between 0 and the maximum length.

Note that maximum-length string fields are variable-length fields with a maximum length defined by the max parameter in the form:


max_s: string [max=10];

In this example, the field max_s is variable length up to 10 bytes long.

By default, the generator operator initializes all bytes of a string field to the same alphanumeric character. When generating a string field, the operators uses the following characters, in the following order:


abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

For example, the following field specification:


s: string[5];

produces successive string fields with the values:


aaaaa 
bbbbb
ccccc
ddddd
...

After the last character, capital Z, values wrap back to lowercase a and the cycle repeats.

Note: The alphabet property for ustring values accepts Unicode characters.

You can use the alphabet property to define your own list of alphanumeric characters used for generated string fields:


alphabet = 'alpha_numeric_string'

This option sets all characters in the field to successive characters in the alpha_numeric_string. For example, this field specification:


s: string[3] {alphabet='abc'};

produces strings with the following values:


aaa 
bbb
ccc
aaa
...
Note: The cycle option for usting values accepts Unicode characters.

The cycle option specifies the list of string values assigned to generated string field:


cycle = { value = 'string_1', value = 'string_2', ... }

The operator assigns string_1 to the string field in the first generated record, string_2 to the field in the second generated record, and so on In addition:

  • If you specify only a single value, all string fields are set to that value.
  • If the generated string field is fixed length, the value string is truncated or padded with the default pad character 0x00 to the fixed length of the string.
  • If the string field contains a maximum length setting, the length of the string field is set to the length of the value string. If the length of the value string is longer than the maximum string length, the value string is truncated to the maximum length.