@String()
New in 2.0Generate random strings
Data TypesSince 2.0.0
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| length | Integer | — | 6 | String length, default 6, max length 2^31-1 characters |
| min | Integer | — | 0 | Minimum length, default 0 (returns empty string "") when not specified. If length is specified, this parameter is ignored |
| max | Integer | — | — | Maximum length, max limit 2^31-1 characters. If length is specified, this parameter is ignored |
| chars | String | — | a-zA-Z0-9 | Character set for string generation. Default: 52 letters (a-z A-Z) and 10 digits (0-9). Max 2^31-1 characters, e.g.: 123456ABCDEF |
| nullSampler | String | — | — | The null ratio, such as "1:2", indicates that generating a random value 3 times with an average of 1 time is null |
Usage
@String()Generate 6-character fixed-length random string
Example:
@String()
Output:
ceja7d@String(length)Generate fixed-length string
Example:
@String(2)
Output:
uyh8@String(length,nullWeight)Generate variable-length string within specified range with null ratio
Example:
@String(3,"1:2")
Output:
ec2nullc3a@String(min,max)Generate random string within specified length range
Example:
@String(2,6)
Output:
ht8utcy@String(length,nullWeight,chars)Generate fixed-length string from custom character set with null ratio
Example:
@String(3,"1:2",abcdef123456)
Output:
ec2f36c3a@String(length,min,max,chars,nullWeight)Full parameter constructor, see complete parameter documentation
Example:
@String(1,,,ABCDE,"1:2")
Output:
AnullBCnull