# Data generation functions

You can generate output data different from the input data.

| Function | Random generation | Consistent generation | Bijective generation | Input data validation |
| --- | --- | --- | --- | --- |
| Generate from pattern | Yes | No | No | No |
| Generate Uuid | Yes | No | No | No |
| Generate sequence | Yes | No | No | No |
| Generate from file/list | Yes | Yes | No | No |

## Generate from pattern

This function generates a value based on a user-defined pattern. This function only applies on Strings.

| Option | Description |
| --- | --- |
| Extra parameter | This function requires an extra parameter.<br><br>The extra parameter is a pattern that<br>follows those rules:<br><br><ul> <li> <span>A</span> is replaced with a                        random Latin uppercase letter.</li> <li> <span>a</span> is replaced with a                        random Latin lowercase letter.</li> <li> <span>9</span> is replaced with a                        random digit.</li> <li> <span>H</span> is replaced with a                        random Hiragana character.</li> <li> <span>K</span> is replaced with a                        random full-width Katakana character.</li> <li> <span>k</span> is replaced with a                        random half-width Katakana character.</li> <li> <span>C</span> is replaced with a                        random Kanji character.</li> <li> <span>G</span> is replaced with a                        random Hangul character.</li> </ul><br><br>All other characters are copied to the generated value<br>as is.<br><br>For more information about the supported<br>character types and the related Unicode ranges, see [Data masking functions in the masking components](https://help.qlik.com/talend/en-US/components/8.0/data-privacy/data-masking-functions-in-masking-components).<br><br>You can also use<br>numbered backreferences (\\&lt;number&gt;) using the following syntax: &lt;pattern&gt;\\&lt;number&gt;,&lt;group1&gt;,&lt;groupN&gt;.<br><br><ul> <li> <kbd>&lt;pattern&gt;</kbd>                        corresponds to the pattern to be used for generating the output                        value.</li> <li> <kbd>\\&lt;number&gt;</kbd>                        is a numbered backreference. <kbd>&lt;number&gt;</kbd> identifies the position of the group                        placed after the "<kbd>,</kbd>"                        character.</li> <li> <kbd>&lt;group1&gt;,&lt;groupN&gt;</kbd> are comma-separated                        groups of characters. Each group is treated as a single unit. If a                        backreference calls a group, it is added as is in the generated                        value.</li> </ul><br><br>If you want to copy a character used in patterns<br>(A, a,<br>9, H,<br>h, K,<br>k, C,<br>G) as is in the generated value, use a<br>backreference. |

This function does not work correctly if a comma ',' is used in the pattern.

In the following example:

* a characters are replaced with random Latin lowercase letters.
* s characters are not masked in the generated output.
* \\2 calls the group placed after the second "," character, which is @talend.com.

| Input value | Extra parameter | Example of a masked value |
| --- | --- | --- |
| A26 | "aaaass\\2,@gmail.com,@talend.com" | hjdfss@talend.com |

In the following example:

* \\3 calls the group placed after the third "," character, which is a.
* 9 characters are masked with random digits.

| Input value | Extra parameter | Example of a masked value |
| --- | --- | --- |
| A26 | "\\39999,D,Z,a" | a4825 |

## Generate UUID

This function masks the input value with a randomly generated universally unique identifier (UUID).

This function uses the UUID.randomUUID() method provided by Java. This Java method does not use a seed, meaning that if you run the job twice, the function generates different UUIDs.

This function is applied on Strings.

This function requires no extra parameter.

In the following example, the masked valued is a randomly generated UUID.

| Input value | Example of a masked value |
| --- | --- |
| A26 | 28e92000-aafa-4ec3-bd56-240f192a4a8c |

## Generate sequence

This function returns the extra parameter, and, for each row, will increase this number by 1.

This function can be applied on all data types but Date (Integer, Long, Strings, etc.).

Information noteNote: This function is not supported in the Spark version of the component.

| Option | Description |
| --- | --- |
| Extra parameter | This function requires an extra parameter.<br><br>The extra parameter must be a number.<br><br>If the extra<br>parameter is not a number, it is set to 0. |

In the following example, the generated sequence starts with the number set as an extra parameter.

| Input values | Extra parameter | Examples of masked values |
| --- | --- | --- |
| 21<br><br>A48 | "0" | 0<br><br>1 |

## Generate from file/list

This function randomly replaces the input value with one of the user-defined values.

This function is applied to Strings or numerical data types.

| Option | Description |
| --- | --- |
| Method | The Randomly method randomly selects the value<br>from the list (or file). As a result, two similar input values can be masked<br>with the different output values.<br><br>The Consistently<br>method ensures that two similar input values are masked with the same output<br>value.<br><br>When using the<br>Consistently method, the probability of<br>generating duplicates can be calculated using the following formulas:<br><br><ul> <li>P = 1 if K &lt; N, or</li> <li>P = 1-K*(K-1)*(K-2)*…*(K-N+1) / K^N</li> </ul><br><br>where P<br>is the probability of generating duplicates, N the input data size and K is the size of the input list given as a<br>parameter.<br><br>Using this approach, it is possible to<br>calculate the probability to find a pair sharing the same value within a<br>group.<br><br>For example, the probability that, in a group<br>of n people, two people have the same birthday is<br>the following:<br><br><ul> <li>2.7% in a group of 5 people,</li> <li>41.1% in a group of 20 people,</li> <li>100% in a group of 367 people, since there are 366                           possible birthdays, including February 29.</li> </ul> |
| Extra parameter | This function requires an extra parameter.<br><br>The extra parameter can be:<br><br><ul> <li>a comma-separated list of two values minimum; or</li> <li>a path to a file containing the values.</li> </ul><br><br>The values must be stored in a String and<br>separated by commas, for example: "item1, item2,<br>item3, etc.". This function uses the hashCode() method provided by Java to choose an element from<br>the list.<br><br>If you use the Apache Spark version of the component, set the file<br>path as follows:<br><br><ul> <li>In local mode:<ul> <li>Apache Spark 3.1 and earlier: <span>prefix://file path</span> or                        <span>file:///file path</span>.</li> <li>Apache Spark 3.2 and later: <span>file:///file path</span>.</li> </ul></li> <li>In Standalone and Yarn modes: <span>prefix://file path</span>.</li> <li>If the index is on a cluster: <span>hdfs://hdpnameservice1/file path</span>.            </li> </ul><br><br>Paths to folders are not supported.<br><br>If the extra parameter is not set, the function returns an empty String or<br>0. |

In the following example, the masked value is one of the values set as extra parameters.

| Input value | Method | Extra parameter | Examples of a masked value |
| --- | --- | --- | --- |
| 21 | Randomly | "help,documentation" | help |